Access Google Maps API using https

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
samesand
Posts: 1
Joined: Wed Apr 03, 2019 2:49 am

Access Google Maps API using https

Post by samesand » Wed Apr 03, 2019 2:54 am

I'm trying to access the google maps API using https, but when I try to access the link using the scrip below I don't get an answer. I believe is because I need to use a certificate, but I haven't found any good documentation on how to do that, is that correct? Any ideas about how use the Google API?


try:
import usocket as _socket
except:
import _socket
try:
import ussl as ssl
except:
import ssl


def getweb(webaddress, use_stream=True):
s = _socket.socket()

ai = _socket.getaddrinfo(webaddress, 443)
print("Address infos:", ai)
addr = ai[0][-1]

print("Connect address:", addr)
s.connect(addr)

s = ssl.wrap_socket(s)
print(s)

if use_stream:
# Both CPython and MicroPython SSLSocket objects support read() and
# write() methods.
s.write(b"GET / HTTP/1.0\r\n\r\n")
print(s.read(4096))
else:
# MicroPython SSLSocket objects implement only stream interface, not
# socket interface
s.send(b"GET / HTTP/1.0\r\n\r\n")
print(s.recv(4096))

s.close()

Post Reply