相关文章推荐
唠叨的鸵鸟  ·  PROC相关-CSDN博客·  2 天前    · 
非常酷的葡萄  ·  C++: ...·  4 月前    · 

Python requests: requests.exceptions.ConnectionError: ('Connection aborted.RemoteDisconnected('远程端关闭连接,无响应')

0 人关注

基本上,我的python代码向某些服务器发送get、put、post等请求,以安装和获取某些应用程序(如Postman集合)。在发送request.post(server.url/reset)后,程序复位,应用程序被删除,但当我再次安装它们并试图发送request.put(url/appID)以启动该特定应用程序时,我得到了错误。代码看起来是这样的。

                app1 = requests.put(url_app,headers = headers, data = data)
                if(app1.status_code == 201):
                    print("\nsuccess!")
                else: 
                    while(app1.status_code != 201):
                        app1 = requests.put(app1,headers=headers) #error indicates line 322 which is this line.
                        if(app1.status_code == 201):
                            print("\nsuccess!")
                            break;
                app2 = requests.put(url_app2,headers = headers, data=data)
                if(app2.status_code == 201):
                    print("success!")
                else: 
                    while(app2.status_code != 201):
                        app2 = requests.put(url_bridge, headers =headers, data = data)
                        if(app2.status_code == 201):
                            print(" success!")
                            break;
                app3 = requests.put(url_app3,headers = headers, data=data)
                if(app3.status_code==201):
                    print("success!")
                else:
                    while(app3.status_code != 201):
                        app3 = requests.put(url_app3,headers=headers,data=data)
                        if(app3.status_code == 201):
                            print("success!")
                            break;

而我得到的错误是这个。

  Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 285, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 400, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 702, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.8/http/client.py", line 1348, in getresponse
    response.begin()
  File "/usr/lib/python3.8/http/client.py", line 316, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.8/http/client.py", line 285, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "tool.py", line 484, in <module>
    elif(val == 'q' or val =='Q'): /// this command quits program
  File "tool.py", line 131, in ask_user
    return choice(user_val)
  File "tool.py", line 436, in choice
    else:
  File "tool.py", line 131, in ask_user
    return choice(user_val)
  File "tool.py", line 419, in choice
    print(response_text)
  File "postman_tool.py", line 131, in ask_user
    return choice(user_val)
  File "tool.py", line 436, in choice
    else:
  File "tool.py", line 131, in ask_user
    return choice(user_val)
  File "tool.py", line 440, in choice
  File "tool.py", line 131, in ask_user
    return choice(user_val)
  File "tool.py", line 462, in choice
    print("Reset successful!")
  File "tool.py", line 131, in ask_user
    return choice(user_val)
  File "tool.py", line 439, in choice
    ask_user() //only asks user for next input command (which request to send basically)
  File "tool.py", line 323, in command_five
    print("\ success!")
  File "/usr/lib/python3/dist-packages/requests/api.py", line 131, in put
    return request('put', url, data=data, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send