tcassou / mapsplotlib

Custom Python plots on a Google Maps background. A flexible matplotlib like interface to generate many types of plots on top of Google Maps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP firbidden error

ankita-upay opened this issue · comments

#%matplotlib inline
import pandas as pd

from mapsplotlib import mapsplot as mplt

mplt.register_api_key('AIza*****************yJDcvyus')
df = pd.read_csv(r'C:\Users\leo_a\Daily_Learning\Thesis_Work\AoT_Chicago.complete.2018-08-08.from-2018-08-02-to-2018-08-08\nodes.csv')
df['latitude']=df['lat']
df['longitude']=df['lon']
new_df=df[['latitude', 'longitude']].copy()
mplt.plot_markers(new_df)

I am trying to mark in the df on gmap but the result of this is

HTTPError: 403 - Forbidden. b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x05\x00\x00\x00\x05\x00\x08\x06\x00\x00\x00\x18\xe4\xff\xf7\x00\x00\x00\x06bKGD\x00\xff\x00\xff\x00\xff\xa0\xbd\xa7\x93\x00\x00 \x00IDATx\xda\xec\xdd\xd9sV\xf7\x99\xe0\xf1GB+\x8b\x84\x80\xb0\x98\xd5\x04\xca,2\x8b'C&\x86\x01\xdcJ\xc7\xdb\xc4\x0e\xa9\xdcLWMn\xa6\xa7\xa7\xab\5]5=\x9e\x9at\xdf\xe4\xba's\xd7\xfe\x17:S\x9d\xc5cw\xec$@\x8cB\x19\xbcT\xc5\x08\x0c\x02\x1c\x9cA\xb2\x8d1\x9b$\x10Bz\xb5\xcdEw<ql\xbf\xafdK:\xf2\xc3\xe7sC\x99\xdf\xef}\xf5\x9c\x83Q\xa9\xbe\x9c\xf7\x9c\xaa\x8b\x17/\x8e\x07\x00\x00\x00\x00\x90Ru\xd1\x03\x00\x00\x00\x00\x00\xd3G\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@\x00\x00\x00\x00HL\x00\x04\x00\x00\x00\x80\xc4\x04@..contd

I am not sure what I am doing something wrong , please guide

well, this might be related to when you use mplt.plot_markers(new_df), you use requests.get() to call a url that contains your api key. See my issue (#12) for details. I re-opened the issue because I think it might be a reoccurring problem.

I was able to sidestep the problem by individually calling the img for the map itself.

Try this code out to get the image.

def get_img(country, zoom, size, scale, maptype):
    # url variable store url
    url  = 'https://maps.googleapis.com/maps/api/staticmap?'
    url += 'center={}&'.format(country)
    url += 'zoom={}&'.format(zoom)
    url += 'scale={}&'.format(scale)
    url += 'size={}x{}&'.format(size, size)
    url += 'maptype={}&'.format(maptype)
    
    r = requests.get(url)
    img = Image.open(StringIO((r.content)))
    
    return img

get_img(country = 'United States', zoom = 4, size = 640, scale = 1, maptype = 'hybrid')

You would have to do something like this to figure out what's going on.

import inspect

print(inspect.getsource(mplt.plot_markers))

Hi @leoankita
As @ChakChak1234 pointed out it could be related to a similar issue (#12), I'll have a look and will get back to you!

As I described in #12 this is happening if you have not set up billing details for your account in the developer console (first 300$ are free). Adding this should fix it!

Please refer to #12 for more context about this issue, thanks again for raising it!