Urequest HTTP Post ECONNRESET

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
reyhg_
Posts: 1
Joined: Wed Mar 23, 2022 1:39 pm

Urequest HTTP Post ECONNRESET

Post by reyhg_ » Wed Mar 23, 2022 1:52 pm

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.

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: Urequest HTTP Post ECONNRESET

Post by ebolisa » Mon Apr 04, 2022 5:14 pm

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 

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Urequest HTTP Post ECONNRESET

Post by karfas » Mon Apr 04, 2022 6:27 pm

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 ?
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

Post Reply