6

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???

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
user404288
  • 61
  • 1
  • 2

4 Answers4

6

You probably need to url-encode the password. You'll see an error like that if the password happens to contain a '/'.

Here's a local example (actual values redacted):

>>> 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'

Encode the password:

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

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

Jean Jordaan
  • 626
  • 8
  • 24
  • This is the right answer - I foolishly didn't escape my `/` character, so adding `safe=''` worked for me, TY :) – Ian Clark Apr 09 '14 at 10:15
1

I agree with muckabout, this is the problem. You're probably used to using this in a browser, which would cause the browser to authenticate with the host. You should probably drop everything before the first @ sign.

have a look at urllib docs, specifically FancyURLOpener which might resolve your issue with authentication.

Yoni H
  • 453
  • 2
  • 7
0

The error message shows that there is some issue with the url that you are preparing. Print and check if this is a valid url.

Ankit Jaiswal
  • 22,859
  • 5
  • 41
  • 64
0

The ':' in the HTTP URL is assumed to precede a port number. You are placing an account name which is not numeric. It must be an integer port value.

muckabout
  • 1,923
  • 1
  • 19
  • 31
  • In addition, you should see if they have a web based API which you can use programmatically. – Noufal Ibrahim Jul 28 '10 at 09:09
  • 10
    This is incorrect. There are three places in which ':' are significant. After the protocol, after the username, and after the domain. In the third place it precedes the port number. In the second place (as used here) it precedes the password. – Jean Jordaan Oct 21 '11 at 10:52