473,695 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A question about the urllib2 ?

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.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data="loginuser =0312889&passwo rd=o127me&domai nid=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 ?

Any help will be appreciated very much , thanks in advance !
Apr 11 '06 #1
4 6690

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.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data="loginuser =0312889&passwo rd=o127me&domai nid=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 !


Apr 11 '06 #2
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.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data="loginuser =0312889&passwo rd=o127me&domai nid=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 !
Apr 12 '06 #3

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.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data="loginuser =0312889&passwo rd=o127me&domai nid=1&refer=1& logintype=
##### "))

In the five '#' above , I must submit some Chinese character , but the
urllib2 complain
for the non-ascii characters .


I guess the server expect that a browser is coming from page
https://202.113.16.223/, so the url should be submitted in the encoding
of page https://202.113.16.223/ which is gb2312.

urllib2.urlopen (urllib2.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data=u"loginuse r=0312889&passw ord=o127me&doma inid=1&refer=1& logintype=
写道".encode( 'gb2312')))

should work

Apr 12 '06 #4
Serge Orlov 写道:
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.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data="loginuser =0312889&passwo rd=o127me&domai nid=1&refer=1& logintype=
##### "))

In the five '#' above , I must submit some Chinese character , but the
urllib2 complain
for the non-ascii characters .


I guess the server expect that a browser is coming from page
https://202.113.16.223/, so the url should be submitted in the encoding
of page https://202.113.16.223/ which is gb2312.

urllib2.urlopen (urllib2.Reques t(url="https://202.113.16.223/php/user_login.php" ,
data=u"loginuse r=0312889&passw ord=o127me&doma inid=1&refer=1& logintype=
写道".encode( 'gb2312')))

should work

Yeah , and it works !
Thank you !

Apr 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4459
by: bmiras | last post by:
I've got a problem using urllib2 to get a web page. I'm going through a proxy using user/password authentification and i'm trying to get a page asking for a HTTP authentification. And I'm using python 2.3 Here is an exemple of the piece of code I use: import urllib2 #Proxy handler proxy_handler = urllib2.ProxyHandler({"http" :
1
3952
by: Matthew Wilson | last post by:
I am writing a script to check on my router's external IP address. My ISP refreshes my IP very often and I use dyndns for the hostname for my computer. My Netgear mr814 router has a webserver that uses HTTP basic authorization. My script uses urllib2 to connect to the router and read the html page with the current external IP address. This is the function I wrote to lookup the router's external IP: def mr814(router_user,...
2
6103
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line #80 and line # 38 are the first line offenders. --> --> -->
5
7403
by: Pascal | last post by:
Hello, I want to acces my OWA (Outlook Web Acces - http Exchange interface) server with urllib2 but, when I try, I've always a 401 http error. Can someone help me (and us)? Thanks. here's my pyscript:
0
2646
by: jacob c. | last post by:
When I request a URL using urllib2, it appears that urllib2 always makes the request using HTTP 1.0, and not HTTP 1.1. I'm trying to use the "If-None-Match"/"ETag" HTTP headers to conserve bandwidth, but if I'm not mistaken, these are HTTP 1.1 headers, so I can't reasonably expect a web server to respond correctly to my requests. (In my limited testing, it looks like some servers respond correctly with an HTTP 304 status, while some...
0
1856
by: Gil Tal | last post by:
Hi, I use urllib2 to download a redirected url and I get an exception from the bowels of urllib2. It seems that urllib2 implements some super sophisticated self check and tries to control the access to attributes using lots of calls to hasattr(the builtin function) and a custom __getattr__() on the Request class that perfroms some checks and raises an AttributeError if it's not happy. The problem is that hasattr() according to the docs is...
1
3368
by: Ray Slakinski | last post by:
Hello, I have defined a function to set an opener for urllib2, this opener defines any proxy and http authentication that is required. If the proxy has authencation itself and requests an authenticated file I get a HTTP status code of 401 (Unauthorized access of the file being requested) I do see in the headers the Proxy-authorization and the Authorization headers being sent for the request.
1
5756
by: Alessandro Fachin | last post by:
I write this simply code that should give me the access to private page with htaccess using a proxy, i don't known because it's wrong... import urllib,urllib2 #input url url="http://localhost/private/file" #proxy set up
2
12387
by: ken | last post by:
Hi, i have the following code to load a url. My question is what if I try to load an invalide url ("http:// www.heise.de/"), will I get an IOException? or it will wait forever? Thanks for any help. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener)
0
8640
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9122
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8860
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4348
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3018
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2280
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1980
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.