ConnectionError of python requests module

I have written a python script which includes a different request access to different endpoint. and I am getting connection error at any random line. Can you please provide any fix/solution for this.

We are using requests module like this…

with requests.Session() as session:
with session.post(url, headers=headers_iq) as response:
data = json.loads(response.content.decode(‘utf-8’))

We cannot help as you are not showing us your code or the error you are seeing.

Include both as preformatted text like this.

your code

[quote=“Ritika Pandey, post:1, topic:28725, full:true, username:ritika123”]
I have written a python script which includes a different request access to different endpoint. and I am getting connection error at any random line. Can you please provide any fix/solution for this.

We are using requests module like this…

with requests.Session() as session:
with session.post(url, headers=headers_iq) as response:
data = json.loads(response.content.decode(‘utf-8’))

and here is the Error:

"C:\Users\SDS\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Your post request does not provide any data. I am assuming that the post() is a http POST.

I expect the server just closed the connect because your post is bad.

Thanks for response, whatever I am passing in session.post() method url, headers_iq all contains a value. sometime code is getting executed successfully but other times it gives connectionError

That sounds like an issue on the server. Can you check the logs on the server?

If not you will need to be able to recover from this error.
Maybe retry after a short delay?

I find it very odd that the api to that server uses post without data.
I would have expected get to be used in that case.

Thanks, Let me explain you the whole process. I am integrating ConnectWise and Incident IIQ, so when I am importing tickets from CW to IIQ, after few tickets getting imported in between I am getting above mentioned, which I am trying to avoid. if I will run the code again manually or using try and except, data is getting overidden in IIQ.

I do not know those services. Can only suggest that you add retry logic to your code in the hope that it is an intermittent issue with the server. You will need to experiment with how long to wait before retrying. Maybe a few seconds but could be hours.