Python: regular urllib.urlopen number

for the following code

theurl = "https://%s:% s@members.dyndns.org /nic/update?hostname=%s&myip=%s&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" % (username, password, hostname, theip) conn = urlopen(theurl) # send the request to the url print(conn.read()) # read the response conn.close() # close the connection 

I get the following error

 File "c:\Python31\lib\http\client.py", line 667, in _set_hostport raise InvalidURL("nonnumeric port: '%s'" % host[i+1:]) 

Any ideas ???

+6
python urllib urlopen
source share
4 answers

You probably need to enter a password for the password. You will see this error if the password contains a '/' character.

Here is a local example (actual values):

 >>> opener <urllib.FancyURLopener instance at 0xb6f0e2ac> >>> opener.open('http://admin: somepass@example.com ') <addinfourl at 3068618924L whose fp = <socket._fileobject object at 0xb6e7596c>> >>> opener.open('http://admin:somepass/ a@example.com ') *** InvalidURL: nonnumeric port: 'somepass' 

Encrypt Password:

 >>> opener.open('http://admin:somepass% 2Fa@example.com ') 

You can use urllib.quote('somepass/a', safe='') for encoding.

+6
source share

I agree with muckabout, this is a problem. You are probably used to using this in a browser, which will lead to authentication of the browser with the host. You should probably leave everything before the first @ sign.

look at urllib docs , in particular FancyURLOpener, which can solve your authentication problem.

+1
source share

The error message indicates that there is some problem with the URL you are preparing. Print and check if this is a valid URL.

0
source share

The assumption is that ':' in the HTTP URL is preceded by a port number. You specify the name of an account that is not numeric. It must be an integer port value.

0
source share

All Articles