http – Python requests.exception.ConnectionError: connection aborted BadStatusLine

http – Python requests.exception.ConnectionError: connection aborted BadStatusLine

The problem was with the url. This connection was meant to be established over https and I was using http in the python script. Hence the issue.

Have you actually checked, what gets send over the wire? I suppose you might have to convert your dictionary to a JSON string by yourself, or use the json= keyword instead of payload=. See http://docs.python-requests.org/en/latest/user/quickstart/#custom-headers for details. This may do the trick:

import json
payload = json.dumps({mac:new_mac,token:token})
userloginurl = http://192.168.1.40:9119/uid
r = requests.get(userloginurl, data=payload)
print(r.url)

http – Python requests.exception.ConnectionError: connection aborted BadStatusLine

I was getting the same error and spent hours on it. I found that you cannot call the flask server in a client using Localhost. It has to be 127.0.0.1

#server
from flask import Flask
app = Flask(__name__)

@app.route(/)
def hello_world():
   return Hello World

if __name__ == __main__:
   app.run(debug=True)

Now the client causing the error:

#client
import requests
x = requests.get(http://localhost:5000) # change it to 127.0.0.1
print(x.text)

Leave a Reply

Your email address will not be published. Required fields are marked *