I'm working on a project which uses an ESP8266 to access the Halo Public API to download game history data which could then be processed and displayed with a seven segment display. However I am have trouble accessing the Halo public API. Using python on my desktop computer I was able to access the API using the request library. When I tried to do the same thing on the ESP8266 using the urequest library I get an error regarding 'INVALID_HANDSHAKE'. I do not have much experience with networking so I am unsure what this means exactly.
Here is the actual error:
Code: Select all
Traceback (most recent call last):
File "/usr/bin/ampy", line 8, in <module>
sys.exit(cli())
File "/usr/lib/python3.9/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.9/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/ampy/cli.py", line 338, in run
output = board_files.run(local_file, not no_output, not no_output)
File "/usr/lib/python3.9/site-packages/ampy/files.py", line 309, in run
self._pyboard.execfile(filename, stream_output=True)
File "/usr/lib/python3.9/site-packages/ampy/pyboard.py", line 285, in execfile
return self.exec_(pyfile, stream_output=stream_output)
File "/usr/lib/python3.9/site-packages/ampy/pyboard.py", line 279, in exec_
raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b"network config: ('192.168.1.203', '255.255.255.0', '192.168.1.1', '192.168.1.1')\r\nMaking an API Call\r\n", b'Traceback (most recent call last):\r\n File "<stdin>", line 86, in <module>\r\n File "<stdin>", line 79, in run\r\n File "<stdin>", line 34, in callAPI\r\n File "urequests.py", line 108, in get\r\n File "urequests.py", line 60, in request\r\nOSError: (-260, \'INVALID_HANDSHAKE\')\r\n')
Here is the code I used for that:
Code: Select all
def getHaloData():
# Connect to the host.
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
addr = socket.getaddrinfo('www.haloapi.com', 80)[0][-1]
client.connect(addr)
# Request data from the host.
path = 'https://www.haloapi.com/stats/h5/players/EnduroCat14/matches HTTP/1.1'
host = 'www.haloapi.com'
key = '••••••••••••••••••••••••••••••••'
client.send(bytes('GET %s\r\nHost: %s\r\nOcp-Apim-Subscription-Key: %s\r\n\r\n' % (path, host, key), 'utf8'))
while True:
data = client.recv(4096)
if data:
print(str(data, 'utf8'))
else:
break
client.close()
Code: Select all
HTTP/1.1 404 Resource Not Found
Content-Length: 54
Content-Type: application/json
Date: Sun, 14 Mar 2021 23:38:27 GMT
{ "statusCode": 404, "message": "Resource not found" }
Code: Select all
GET https://www.haloapi.com/stats/h5/players/EnduroCat14/matches HTTP/1.1
Host: www.haloapi.com
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••
Any help would be greatly appreciated. I would love to use the ESP8266 and micropython to power my project, but I am pretty stuck. Thanks in advance!