Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Urequests error while sending HTTPS requests. #81

Open
Aman2210200 opened this issue May 15, 2023 · 0 comments
Open

Urequests error while sending HTTPS requests. #81

Aman2210200 opened this issue May 15, 2023 · 0 comments

Comments

@Aman2210200
Copy link

Hi there, i want to post my sensor data to my backend server. For that i used urequests library.

But i am getting the error status code of 426 which ingeneral means upgrade required. I want to kow how i can solve this problem.

i have attached the code i used
also i have checked urequests is using http 1.0, how to ugrade that also coz it is obselete now

`import machine
import urequests as requests
import network
import time
import ujson

Wifi Credentials

SSID = "xxxx"
PSK = "xxxxx"

def connect_to_wifi(ssid, psk):
# Enable Wifi in Client Mode
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Connect to Wifi, keep trying until failure or success
wlan.connect(ssid, psk)

while not wlan.isconnected() and wlan.status() >= 0:
    print("Waiting to Connect")
    time.sleep(5)
if not wlan.isconnected():
    raise Exception("Wifi not available")
print("Connected to WiFi")

connect_to_wifi(SSID, PSK)

while True:
try:

    url = "https://backend-production-e1c2.up.railway.app/api/auth/createuser"
    headers = { "Content-Type": "application/json" }
   
    insertPayload = ujson.dumps({ 'name':'sample tsdasdfsdfing','email':'harshisgood@gmaifdfsfl.com', 'password':'784989012sdfsdf4'})
    
    print("sending...")
    
    start_time = time.ticks_ms()
    
    response = requests.post(url, headers=headers, data =insertPayload)
    
    end_time = time.ticks_ms()
    content = response.headers
    print(content)
  
    print("Response: (" + str(response.status_code) + "), msg = " + str(response.text))

    if response.status_code == 201:
        print("Added Successfully")
    else:
        print("Error")

    # Always close response objects so we don't leak memory
    response.close()
    elapsed_time = end_time - start_time
    print("Request time: {} ms".format(elapsed_time))

except Exception as e:
    print(e)

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant