psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
51.6k stars 9.23k forks source link

Post Request Status and header error. #6657

Closed b4el7d closed 2 months ago

b4el7d commented 2 months ago

I am currently involved in a project where it is necessary to send POST requests to a remote server. I have noticed unexpected behavior when trying to emulate a POST request that I receive from Mozilla Firefox.

Specifically, when I perform the POST request through Mozilla Firefox, I receive a response with HTTP/0.9 without headers and a reported status of 200. However, when I try to emulate the same POST request in Python 3 using the requests library, I do not receive any status code, and I encounter an error "raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine('\n'))".

After a more in-depth analysis, I discovered that the server is responding with HTTP/0.9, which may be the cause of the problem. However, I am unable to obtain a valid status code using requests.

To temporarily resolve the issue, I modified the behavior of the _read_status(self) function in the requests library to convert the first line into a valid status code. I also simulated the presence of the line "line = b'\r\n'" in the header to avoid issues when reading the headers.

How can I correctly interpret the response from the server? My request header is as follows:

Here is the code: ` import requests

uid = "3491282510" url = f'https://10.97.80.44/goform/formPostData?LE=ethPortCfg&UID={uid}' print(url)

headers = { "User-Agent": "Mozilla/5.0", "Accept": "application/xhtml+xml", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, bz" }

data = { 'fd0': '0/2', 'fd1': 'Port 2', 'fd2': '0/2', 'fd3': '1000X', 'fd4': 'Disabled', 'fd5': 'On', 'fd6': '1G', 'fd7': 'Full', 'fd8': 'Off', 'fd9': 'Off', 'fd10': 'On', 'fd11': 'Do nothing', 'fd12': 'N/A', 'fd13': '5', 'choice': 'Apply' }

response = requests.post(url, headers=headers, data=data, verify=False) print(response.status_code)

Output the response content

print(response.text) ` How i can solve this issue? ty

github-actions[bot] commented 2 months ago

As described in the template, we won't be able to answer questions on this issue tracker. Please use Stack Overflow