Skip to content

Urequests error while sending HTTPS requests. #81

@Aman2210200

Description

@Aman2210200

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)

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions