Velocity Reviews

Velocity Reviews (
-   Python (
-   -   Re: Strings and Unicode (

John Machin 07-20-2003 01:47 PM

Re: Strings and Unicode (-) wrote in message news:< 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
>>> import urllib
>>> foo = urllib.urlencode({'foo':42,'bar':69})
>>> type(foo)

<type 'str'>
>>> foo

>>> foo = urllib.urlencode('abcdef')

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:\python22\lib\", 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.