weixin_40215295
骑蜗牛旅行
2017-09-12 14:45

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

  • 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条回答