HTTP Requests with basic auth

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Nogga
Posts: 4
Joined: Thu Apr 27, 2017 7:47 pm

HTTP Requests with basic auth

Post by Nogga » Thu Apr 27, 2017 7:54 pm

I am using the urequests lib from https://github.com/micropython/micropyt ... equests.py

I have tried out many different approaches (sorry, I can't remember them all).

Any snippet which shows how to achieve a proper GET and POST (with payload) requests while utilizing basic auth?

Thank you very much!

Nogga
Posts: 4
Joined: Thu Apr 27, 2017 7:47 pm

Re: HTTP Requests with basic auth

Post by Nogga » Fri Apr 28, 2017 8:13 pm

I was now able to actually get some response:

import urequests
import json

headers = {'Authorization': 'Basic dGVzdDp0ZXN0'} # test:test
r = urequests.get("http://httpbin.org/basic-auth/test/test", headers=headers)
print(r.json())

This gives me the correct response:
{'authenticated': True, 'user': 'test'}

But if I now try to do exactly the same request to a httpS-host (httpS://httpbin.org/basic-auth/test/test), it raises the following error:

ssl_handshake_status: -80
Traceback (most recent call last):
File "<stdin>", line 67, in <module>
File "<stdin>", line 57, in get_data
File "urequests.py", line 101, in get
File "urequests.py", line 56, in request
OSError: [Errno 5] EIO

I think the error lies in the SSL handshake, but I do not know what to do.

Any advice, hints?

buttiense
Posts: 1
Joined: Tue May 09, 2017 1:34 pm

Re: HTTP Requests with basic auth

Post by buttiense » Tue May 09, 2017 1:37 pm

Did you solve this problem?
I am stuck on the same fault, but don't know how to solve it..

thijsdv
Posts: 5
Joined: Mon Jan 30, 2017 8:35 am

Re: HTTP Requests with basic auth

Post by thijsdv » Thu May 11, 2017 9:51 am

I have the same issue on the ESP and unix.

Could this be an axtls issue?

alex-robbins
Posts: 1
Joined: Wed Jul 12, 2017 7:30 pm

Re: HTTP Requests with basic auth

Post by alex-robbins » Wed Jul 12, 2017 7:46 pm

When I see "ssl_handshake_status: -80", it's because I didn't pass server_hostname to ussl.wrap_socket. See urequests/urequests.py from micropython-lib for an example.

The server_hostname parameter is for TLS's Server Name Indication (SNI), support for which was recently added to MicroPython via upstream changes to axTLS (https://github.com/micropython/micropython/issues/3140).

Post Reply