A question about the urllib2 ?

Bo Yang struggleyb at gmail.com
Wed Apr 12 04:05:05 EDT 2006


Fuzzyman 写道:
> Bo Yang wrote:
>   
>> Hi ,
>> Recently I use python's urllib2 write a small script to login our
>> university gateway .
>> Usually , I must login into the gateway in order to surf the web . So ,
>> every time I
>> start my computer , it is my first thing to do that open a browser to
>> login the gateway !
>>
>> So , I decide to write such a script , sending some post information to
>> the webserver
>> directly to login automatic once the computer is on . And I write the
>> code below :
>>
>> urllib2.urlopen(urllib2.Request(url="https://202.113.16.223/php/user_login.php",
>> data="loginuser=0312889&password=o127me&domainid=1&refer=1& logintype=
>> #####"))
>>
>> In the five '#' above , I must submit some Chinese character , but the
>> urllib2 complain
>> for the non-ascii characters .
>>
>> What do you think this ?
>>
>>     
> I haven't tried this, so I'm guessing :-)
>
> Do you pass in the string to urllib2 as unicode ? If so, try encoding
> it to UTF8 first...
>
> Otherwise you might try escaping it using ``urllib.quote_plus``. (Note
> ``urllib``, *not* ``urllib2``.)
>
> All the best,
>
> Fuzzyman
> http://www.voidspace.org.uk/python/index.shtml
>
>   
>> Any help will be appreciated very much , thanks in advance !
>>     
>
>   
Thank you , I have got it !
I quote the Chinese with urllib.quote() ,
Thanks again !



More information about the Python-list mailing list