骑蜗牛旅行 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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择