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