urllib.request错误!!没有主持人

时间:2015-12-30 20:34:40

标签: python python-3.x urllib

我对Python很新,目前正在学习它。我有这个小代码:

import urllib.request

x = urllib.request.urlopen('https:\\www.google.com')

print(x.read())

当我运行它时,Python会喊出这个错误:

Traceback (most recent call last):
File "C:/Users/The Kids/Desktop/urllib.py", line 3, in <module>
x = urllib.request.urlopen('https:\\www.google.com')
File "C:\Program Files\Python35-32\lib\urllib\request.py", line 162, in                    
urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\Python35-32\lib\urllib\request.py", line 463, in open
req = meth(req)
File "C:\Program Files\Python35-32\lib\urllib\request.py", line 1163, in             
do_request_
raise URLError('no host given')
urllib.error.URLError: <urlopen error no host given>

我能帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

网址应为:https://www.google.com。不是https:\\www.google.com。更改网址,它应该有效。