Error method post Requests in python

1

I'm doing a script that makes me a POST method. I follow the library documentation requests . I have to make a login; when I use the method GET no error arises. It consists of several tags with enable ( value=1 ) and disable ( value=0 ), and at the end of the form has a tag apply changes . Anyway, I have this:

import requests
from requests.auth import HTTPBasicAuth
import json


x = {
    "MbssIndexChanged":1,
    "GuestkEnable":1,
    "GuestServiceSetIdentifier":"guest",
    "commitwlanGuestNetwork":1
}

headers = {'User-Agent': 'Mozilla/5.0'}
session = requests.Session()
r = session.post(url, auth=HTTPBasicAuth('user','pass'), data=json.dumps(x))

And I get this error.

Traceback (most recent call last):
  File "/home/ubuntu/workspace/post.py", line 23, in <module>
    r = session.post(url, auth=HTTPBasicAuth(user,pass), data=json.dumps(data))
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 497, in post
    return self.request('POST', url, data=data, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 455, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 558, in
send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=url, port=8080): Max retries exceeded with url: /url (Caused by <class 'socket.error'>: [Errno 104] Connection reset by peer)'

I've tried with the retries=False , with verify=False and without the session , but without result.

    
asked by ellipsys 05.10.2016 в 15:58
source

1 answer

1
[Errno 104] Connection reset by peer

This means that the server where you want to make the post is closing the connection, either because you are doing too many queries or because your POST is poorly armed.

Usually the reason for the error is given in the text parameter of the object r you are getting at the end so as last line do a

print r.text

And look what it says, maybe it's something trivial. I hope you have been useful.

    
answered by 19.10.2016 в 01:28