鱼C论坛

 找回密码
 立即注册
查看: 853|回复: 4

[已解决]055讲隐藏,按照视频敲得代码出错,有没有大佬指导一波

[复制链接]
发表于 2019-4-10 22:19:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import urllib.request

  2. url='http://www.ip.cn/'

  3. proxy_support = urllib.request.ProxyHandler({'https':'60.190.250.120'})

  4. opener = urllib.request.build_opener(proxy_support)

  5. opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6776.400 QQBrowser/10.3.2577.400')]

  6. urllib.request.install_opener(opener)

  7. response=urllib.request.urlopen(url)

  8. html=response.read().decode('utf-8')

  9. print(html)
复制代码


运行之后显示:
Traceback (most recent call last):
  File "E:\Python\lib\urllib\request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "E:\Python\lib\http\client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "E:\Python\lib\http\client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "E:\Python\lib\http\client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "E:\Python\lib\http\client.py", line 1016, in _send_output
    self.send(msg)
  File "E:\Python\lib\http\client.py", line 956, in send
    self.connect()
  File "E:\Python\lib\http\client.py", line 1384, in connect
    super().connect()
  File "E:\Python\lib\http\client.py", line 928, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "E:\Python\lib\socket.py", line 727, in create_connection
    raise err
  File "E:\Python\lib\socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\82539\Desktop\ceshi1.py", line 13, in <module>
    response=urllib.request.urlopen(url)
  File "E:\Python\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "E:\Python\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "E:\Python\lib\urllib\request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "E:\Python\lib\urllib\request.py", line 563, in error
    result = self._call_chain(*args)
  File "E:\Python\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "E:\Python\lib\urllib\request.py", line 755, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "E:\Python\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "E:\Python\lib\urllib\request.py", line 543, in _open
    '_open', req)
  File "E:\Python\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "E:\Python\lib\urllib\request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "E:\Python\lib\urllib\request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
最佳答案
2019-4-10 22:40:24
代理IP不行。换代理IP吧。估计也很难找得到
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-4-10 22:40:24 | 显示全部楼层    本楼为最佳答案   
代理IP不行。换代理IP吧。估计也很难找得到
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-4-10 22:42:58 | 显示全部楼层
网页链接已失效
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-4-10 22:53:55 | 显示全部楼层
ba21 发表于 2019-4-10 22:40
代理IP不行。换代理IP吧。估计也很难找得到

UnicodeEncodeError: 'ascii' codec can't encode characters in position 36-39: ordinal not in range(128)
追问一下哈,如果出现这个错误是什么原因
代码是直接复制小甲鱼055讲作业1的代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-4-10 22:54:25 | 显示全部楼层

我再研究一下吧,总觉得此事必有蹊跷
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-18 11:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表