By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,050 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,050 IT Pros & Developers. It's quick & easy.

UTF problem?

P: n/a
I am trying to set up Linux printing via Windows XP and using this HOWTO:

http://justin.yackoski.name/winp/

I have one problem. When I send a file via CUPS to the windows spool
directory dirwatch.py (http://justin.yackoski.name/winp/dirwatch.txt) dies
and gives:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0'
in position 77: ordinal not in range (128)

I think that this has something to do with UTF-8 what I do not know is how
to get over it?

So could someone please help me to get dirwatch.py script to understand my
filenames (which, btw, do not have any non-ascii symbols, and will work
if I manually copy-rename them).

Thanks in advance!

Vesa-Matti

--
Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * *
mailto:sa******@koivu.oulu.fi * Music seems to help the pain *
Lecturer, mathematics education * R.I.P. Syd, my hero *
University of Oulu, Finland * * * * * * * * * * * * * * * * *

Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Vesa-Matti Sarenius wrote:
I am trying to set up Linux printing via Windows XP and using this HOWTO:

http://justin.yackoski.name/winp/

I have one problem. When I send a file via CUPS to the windows spool
directory dirwatch.py (http://justin.yackoski.name/winp/dirwatch.txt) dies
and gives:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0'
in position 77: ordinal not in range (128)

I think that this has something to do with UTF-8 what I do not know is how
to get over it?

So could someone please help me to get dirwatch.py script to understand my
filenames (which, btw, do not have any non-ascii symbols, and will work
if I manually copy-rename them).
Well you don't say what line it's dying on, but I would guess
it's the line which says "print full_filename" (altho' it
could be when it prints the output from gsprint.exe). In
any case, \xa0 is a non-breaking space:

<code>
import unicodedata

print unicodedata.name (u"\xa0")
</code>

so it's just possible that one of your filenames has
a non-ascii char in it without your noticing? (Altho'
I'd find that an odd character to include in a filename).

ReadDirectoryChangesW is the Unicode version of the
ReadDirectoryChanges API, so always returns Unicode objects
even if there are no non-ascii chars in the filenames.

To get round the problem in the immediate term, change
both print lines to something like:

print repr (full_filename)

This will show exactly what's in the filename. To do
the thing properly, you'll want to encode the filename
to something standard, eg, sys.stdout.encoding or just
"utf8":

print full_filename.encode ("utf8")

but since these are just info outputs I imagine you're
not too bothered how they look.

TJG
Jun 27 '08 #2

P: n/a
In article <ma***************************************@python. org>, Tim Golden wrote:
>so it's just possible that one of your filenames has
a non-ascii char in it without your noticing? (Altho'
I'd find that an odd character to include in a filename).
There is somewhere since printing worked when I changed the filename
completely.
>To get round the problem in the immediate term, change
both print lines to something like:

print repr (full_filename)
This did not work. Neither did commenting all print lines. The problem is
somewhere else.

Strange...

The bash script that copies-renames the file for dirwatch.py is here:

http://justin.yackoski.name/winp/winp

I cannot see where they put a non ascii character there. Can you?

--
Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * *
mailto:sa******@koivu.oulu.fi * Music seems to help the pain *
Lecturer, mathematics education * R.I.P. Syd, my hero *
University of Oulu, Finland * * * * * * * * * * * * * * * * *

Jun 27 '08 #3

P: n/a
Vesa-Matti Sarenius wrote:
This did not work. Neither did commenting all print lines. The problem is
somewhere else.
As Tim said, the line number that the exception prints would help here.

Stefan
Jun 27 '08 #4

P: n/a
In article <sl*********************@sun3.oulu.fi>, Vesa-Matti Sarenius wrote:
>In article <ma***************************************@python. org>, Tim Golden wrote:
>>so it's just possible that one of your filenames has
a non-ascii char in it without your noticing? (Altho'
I'd find that an odd character to include in a filename).

There is somewhere since printing worked when I changed the filename
completely.
I found the problem place, it is:

cmd = '''"C:\\Program Files\\Ghostgum\\gsview\\gsprint.exe" -color ''' +
full_filename

and with that the full_filename has something utf. I tried repr or .encode
("utf8") there but got "file not found" althougt the script itself worked.

--
Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * *
mailto:sa******@koivu.oulu.fi * Music seems to help the pain *
Lecturer, mathematics education * R.I.P. Syd, my hero *
University of Oulu, Finland * * * * * * * * * * * * * * * * *

Jun 27 '08 #5

P: n/a
In article <48**************@behnel.de>, Stefan Behnel wrote:
>Vesa-Matti Sarenius wrote:
>This did not work. Neither did commenting all print lines. The problem is
somewhere else.

As Tim said, the line number that the exception prints would help here.
See my followup...

--
Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * *
mailto:sa******@koivu.oulu.fi * Music seems to help the pain *
Lecturer, mathematics education * R.I.P. Syd, my hero *
University of Oulu, Finland * * * * * * * * * * * * * * * * *
Jun 27 '08 #6

P: n/a
In article <p8******************************@earthlink.com> , Dennis Lee Bieber wrote:
>(Vesa-Matti Sarenius) declaimed the following in comp.lang.python:
And what reported the file not found -- some line of the Python
script, or a spawned shell (since the line you point out is just
creating a command to be executed a subprocess of some sort)
I think that would be the gsprint.exe.
> The other matter would be: is the shell that command is passed off
to using the same encoding?
That would be the windows shell (command prompt) and I know so little of
windows so I would not know...

--
Vesa-Matti Sarenius, M.Sc. * * * * * * * * * * * * * * * * *
mailto:sa******@koivu.oulu.fi * Music seems to help the pain *
Lecturer, mathematics education * R.I.P. Syd, my hero *
University of Oulu, Finland * * * * * * * * * * * * * * * * *
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.