骑蜗牛旅行 2017-09-12 14:45 采纳率: 0%
浏览 2057

【急求解答】Python http进行url访问时报错

代码部分如下(MyPython.py):
r_ip = "xxx.xxx.xxx.xxx"
r_port = 8080
url = 'http://xxx.xxx.xxx.xxx:8080/aop/rest?'
geturl = url+urlPara.decode('gbk').encode('utf-8')
print("geturl=[%s]" % geturl)

conn = httplib.HTTPConnection(r_ip, r_port)
conn.request("GET", geturl)
response = conn.getresponse()
data = response.read()
print("data=[%s]" % data)
conn.close()

执行MyPython.py报错如下:
Traceback (most recent call last):
File "MyPythonTest.py", line 198, in
do_work()
File "MyPythonTest.py", line 182, in do_work
conn.request("GET", geturl)
File "/opt/freeware/lib/python2.7/httplib.py", line 973, in request
self._send_request(method, url, body, headers)
File "/opt/freeware/lib/python2.7/httplib.py", line 1007, in _send_request
self.endheaders(body)
File "/opt/freeware/lib/python2.7/httplib.py", line 969, in endheaders
self._send_output(message_body)
File "/opt/freeware/lib/python2.7/httplib.py", line 829, in _send_output
self.send(msg)
File "/opt/freeware/lib/python2.7/httplib.py", line 791, in send
self.connect()
File "/opt/freeware/lib/python2.7/httplib.py", line 772, in connect
self.timeout, self.source_address)
File "/opt/freeware/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 78] A remote host did not respond within the timeout period.

才开始学习Python不久,对其不太明白,还请大师解答。

  • 写回答

3条回答 默认 最新

  • threenewbee 2017-09-13 00:55
    关注

    超时没有响应,你的地址端口是否正确,网络能否连上。

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝