|
5鱼币
- import urllib.request
- url = 'http://www.whatismyip.com'
- proxy_support = urllib.request.ProxyHandler({'http':'36.25.243.51:80'})
- opener = urllib.request.build_opener(proxy_support)
- opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36')]
- urllib.request.install_opener(opener)
- response = urllib.request.urlopen(url)
- html = response.read().decode('utf-8')
- print(html)
复制代码
- Traceback (most recent call last):
- File "D:\python\文件\17.py", line 11, in <module>
- response = urllib.request.urlopen(url)
- File "D:\python\lib\urllib\request.py", line 222, in urlopen
- return opener.open(url, data, timeout)
- File "D:\python\lib\urllib\request.py", line 531, in open
- response = meth(req, response)
- File "D:\python\lib\urllib\request.py", line 641, in http_response
- 'http', request, response, code, msg, hdrs)
- File "D:\python\lib\urllib\request.py", line 569, in error
- return self._call_chain(*args)
- File "D:\python\lib\urllib\request.py", line 503, in _call_chain
- result = func(*args)
- File "D:\python\lib\urllib\request.py", line 649, in http_error_default
- raise HTTPError(req.full_url, code, msg, hdrs, fp)
- urllib.error.HTTPError: HTTP Error 403: Forbidden
复制代码
各位帮帮忙,刚学,没找出原因是啥 |
|