Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Strings and Unicode (http://www.velocityreviews.com/forums/t319914-re-strings-and-unicode.html)

John Machin 07-20-2003 01:47 PM

Re: Strings and Unicode
 
madsurfer2000@hotmail.com (-) wrote in message news:<fef0a228.0307200027.2ef962e9@posting.google. com>...
> I have a function that takes a string as an input parameter. This
> function then urlencodes the string and sends it to a server with
> telnetlib.Telnet
>
> The problem is that the string gets converted into what seems to be
> Unicode. How can I check to see if the input-string is Unicode and
> convert it to a different character set (in this case ISO-Latin1).


You don't/can't urlencode a string. You urlencode a bunch of
(key,value) strings which are represented as "a mapping object or a
sequence of two-element tuples" so sayeth the documentation. See
below. Passing a string attracts a TypeError. See below. If you
provide a simple example of what you are doing, plus the output that
"seems to be Unicode", plus of course the input that cause the strange
output, we may be able to help you further.

Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on
win32
>>> import urllib
>>> foo = urllib.urlencode({'foo':42,'bar':69})
>>> type(foo)

<type 'str'>
>>> foo

'foo=42&bar=69'
>>> foo = urllib.urlencode('abcdef')

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:\python22\lib\urllib.py", line 1171, in urlencode
raise TypeError
TypeError: not a valid non-string sequence or mapping object
>>>



All times are GMT. The time now is 07:44 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.