NotImplementedError: Redirects not yet supported

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
maytham
Posts: 2
Joined: Tue Sep 29, 2020 2:17 pm

NotImplementedError: Redirects not yet supported

Post by maytham » Tue Sep 29, 2020 2:23 pm

Hi all!

I'm (pretty new to micropython and) trying to use this code from github to add ota updating to my esp32 board: https://github.com/rdehuyss/micropython ... updater.py
however, I get the "NotImplementedError: Redirects not yet supported" error, right after a get a "Location" in the s.readline(). it is trying to redirect to https://api.github.com/repositories/299540267/contents/
how can I get around this?


Code: Select all

ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
        ai = ai[0]

        s = usocket.socket(ai[0], ai[1], ai[2])
        try:
            s.connect(ai[-1])
            if proto == 'https:':
                s = ussl.wrap_socket(s, server_hostname=host)
            s.write(b'%s /%s HTTP/1.0\r\n' % (method, path))
            if not 'Host' in headers:
                s.write(b'Host: %s\r\n' % host)
            # Iterate over keys to avoid tuple alloc
            for k in headers:
                s.write(k)
                s.write(b': ')
                s.write(headers[k])
                s.write(b'\r\n')
            # add user agent
            s.write('User-Agent')
            s.write(b': ')
            s.write('MicroPython OTAUpdater')
            s.write(b'\r\n')
            if json is not None:
                assert data is None
                import ujson
                data = ujson.dumps(json)
                s.write(b'Content-Type: application/json\r\n')
            if data:
                s.write(b'Content-Length: %d\r\n' % len(data))
            s.write(b'\r\n')
            if data:
                s.write(data)

            l = s.readline()
            # print(l)
            l = l.split(None, 2)
            status = int(l[1])
            reason = ''
            if len(l) > 2:
                reason = l[2].rstrip()
            while True:
                l = s.readline()
                if not l or l == b'\r\n':
                    break
                # print(l)
                if l.startswith(b'Transfer-Encoding:'):
                    if b'chunked' in l:
                        raise ValueError('Unsupported ' + l)
                elif l.startswith(b'Location:') and not 200 <= status <= 299:
                    raise NotImplementedError('Redirects not yet supported')
        except OSError:
            s.close()
            raise

printing l:

Code: Select all

b'Date: Tue, 29 Sep 2020 13:41:15 GMT\r\n'
b'Content-Type: text/html;charset=utf-8\r\n'
b'Content-Length: 0\r\n'
b'Connection: close\r\n'
b'Server: GitHub.com\r\n'
b'Status: 302 Found\r\n'
b'Location: https://api.github.com/repositories/299540267/contents/\r\n'


Many Thanks!
Maytham

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: NotImplementedError: Redirects not yet supported

Post by jimmo » Thu Oct 01, 2020 12:52 pm

There have been some attempts to add redirection support to urequests. None of them are merged yet, however you could try copying their implementations. See

https://github.com/micropython/micropython-lib/pull/398
https://github.com/micropython/micropython-lib/pull/378
https://github.com/micropython/micropython-lib/pull/368

maytham
Posts: 2
Joined: Tue Sep 29, 2020 2:17 pm

Re: NotImplementedError: Redirects not yet supported

Post by maytham » Sat Oct 03, 2020 1:45 pm

Thank you so much!

mr-engin3er
Posts: 3
Joined: Fri May 07, 2021 10:40 am

Re: NotImplementedError: Redirects not yet supported

Post by mr-engin3er » Fri May 07, 2021 10:42 am

Hey @maytham
I'm facing the same issue while using Micropython Ota Updater.
Did you solve the problem?
If you solved please share.

SpotlightKid
Posts: 463
Joined: Wed Apr 08, 2015 5:19 am

Re: NotImplementedError: Redirects not yet supported

Post by SpotlightKid » Fri May 07, 2021 11:57 pm

You might be interested in my improved version of urequests, which supports redirects:

viewtopic.php?f=15&t=10454

mr-engin3er
Posts: 3
Joined: Fri May 07, 2021 10:40 am

Re: NotImplementedError: Redirects not yet supported

Post by mr-engin3er » Wed Jul 21, 2021 5:56 am

I solved this error in my Micropython OTA updater repo which is forked from rdehuyss/micropython-ota-updater.

Repo URL:- https://github.com/mr-engin3er/micropython-ota-updater

Post Reply