473,800 Members | 2,648 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 6700

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
4463
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
3965
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
6120
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
7413
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
2659
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
1865
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
3374
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
5762
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
12402
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
9690
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10501
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...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
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
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
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
4149
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.