Re: Strings and Unicode

Discussion in 'Python' started by John Machin, Jul 20, 2003.

  1. John Machin

    John Machin Guest

    (-) wrote in message news:<>...
    > 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
    >>>
     
    John Machin, Jul 20, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    767
    Malcolm
    Jun 24, 2006
  2. Asterix
    Replies:
    5
    Views:
    722
    Matt Nordhoff
    Aug 31, 2008
  3. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    968
    Grzegorz ¦liwiñski
    Jan 19, 2011
  4. Chirag Mistry
    Replies:
    6
    Views:
    172
    Ollivier Robert
    Feb 8, 2008
  5. Terry Reedy
    Replies:
    0
    Views:
    75
    Terry Reedy
    Jan 7, 2014
Loading...

Share This Page