Page 1 of 1

Urequest HTTP Post ECONNRESET

Posted: Wed Mar 23, 2022 1:52 pm
by reyhg_
Hello,

I am trying to upload data from sensor to sql with my ESP32 via http post. I create localhost with XAMPP and want to try to upload data using urequest library but get error massage ECONNRESET. Here my code.

Code: Select all

import urequests as requests
import json
url="http://127.0.0.1/esp_send.php/"
send={"s1":"11187","s2":"65","s3":"54","s4":"1"}
head={'Content-Type': 'application/x-www-form-urlencoded'}
r=requests.post(url=url, data=json.dumps(send), headers=head)
results = r.json()
print(results)
After i run it, i get this error massage

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
  File "urequests.py", line 120, in post
  File "urequests.py", line 60, in request
OSError: [Errno 104] ECONNRESET
In python i tried using this code and found no problem.

Code: Select all

import requests
url="http://127.0.0.1/esp_send.php/"
data={"s1":"11","s2":"12","s3":"13","s4":"14"}
resp = requests.post(url, params=data)
Please any help is highly appreciated. Thanks in advance.

Edit
I change the ip to IPv4 Address and turn of firewall but another problem occur. In mysql it just send empty string and i dont know what wrong.

Re: Urequest HTTP Post ECONNRESET

Posted: Mon Apr 04, 2022 5:14 pm
by ebolisa
You should post the php code.
Anyway, try this:

Code: Select all

# sending post request and saving response as response object
URL="http://127.0.0.1/esp_send.php/"
DATA={"s1":"11187","s2":"65","s3":"54","s4":"1"}
r = requests.post(url = URL, data = DATA)
# extracting response text
url_response = r.text
print("The response from URL is:%s"%url_response) # prints a feedbac from the php file 

Re: Urequest HTTP Post ECONNRESET

Posted: Mon Apr 04, 2022 6:27 pm
by karfas
reyhg_ wrote:
Wed Mar 23, 2022 1:52 pm

Code: Select all

url="http://127.0.0.1/esp_send.php/"
# ...
r=requests.post(url=url, data=json.dumps(send), headers=head)
I think you should add the address of the server where your PHP script is running.
Your code might be great to try it out on the server, but 127.0.0.1 is always localhost (the machine where the script runs).

Maybe a little reading about TCP basics might help ?