use*_*288 6 python urllib urlopen
对于以下代码
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
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
File "c:\Python31\lib\http\client.py", line 667, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
Run Code Online (Sandbox Code Playgroud)
有任何想法吗???
您可能需要对密码进行url编码.如果密码恰好包含'/',您将看到类似的错误.
这是一个本地示例(实际值已编辑):
>>> 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'
Run Code Online (Sandbox Code Playgroud)
编码密码:
>>> opener.open('http://admin:somepass%2Fa@example.com')
Run Code Online (Sandbox Code Playgroud)
您可以使用urllib.quote('somepass/a', safe='')进行编码.
| 归档时间: |
|
| 查看次数: |
8516 次 |
| 最近记录: |