[ Python socket.py gaierror when trying to use Google Maps API ]
I'm using socket.py's create_connection method to connect to Google Maps API, I think the way I'm using it is giving me an error. When I try this with a host such as www.python.org everything works fine. What's the issue that I can't understand.
>>> socket.create_connection(("www.maps.googleapis.com/maps/api/geocode/json?address=L5R2W9&key=******", 443))
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 8] nodename nor servname provided, or not known
Answer 1
The socket
module is too low-level for making the type of HTTP requests you are thinking. If you really want to make a socket connection to www.googleapis.com
, try this instead:
socket.create_connection(("www.maps.googleapis.com", 443))
If you want to make an actual HTTP request, you can try the requests
module instead:
import requests
requests.get("https://www.maps.googleapis.com/maps/api/geocode/json?address=L5R2W9&key=******")