error in googlemaps in python - python

I have the python google maps for python. i have this code:
from googlemaps import GoogleMaps
place1 = raw_input("your address: ")
place = raw_input("Destination: ")
gmaps = GoogleMaps(api_key)
directions = gmaps.direction(place1, place)
for step in directions['Directions']['Routes']['seconds'][0]['Steps']:
print step['descriptionHtml']
and i get this error
Traceback (most recent call last):
File "C:\Python27\test.py", line 152, in <module>
directions = gmaps.direction(place1, place)
AttributeError: 'GoogleMaps' object has no attribute 'direction'
i'm trying to ask the user for their address and the Destination and then find the directions.

It looks like the method is actually GoogleMaps.directions(origin, destination, **kwargs), notice the "s" on the method name. Here's a link to the API docs.

Sounds like you don't have a Google Maps API key. You need to sign up for one here:
https://developers.google.com/maps/documentation/javascript/tutorial#api_key
By the way, when you say "the python google maps for python," what are you referring to exactly? Is it this project?

Related

Pyhton USGS EarthExplorer API not Working

I am trying to write a pyhton script that I would have my login credientals to log into USGS earth explorer and use their API to search for images in a dataset and give me the results, I am not sure what I want to do with the results but I am having trouble even searching for anything using the api.
Here is the code I have:
from usgs import api
#USGS EarthExplorer username and password
username = ''
password = ''
# Connect to the USGS EarthExplorer API using username and password
# This will prompt you to enter your credentials if you haven't set them up already
api.login(username, password)
# Search for Landsat 8 images within a specific date range and location
# In this example, we are searching for images over Washington, D.C. from January 1, 2022 to February 1, 2022
result = api.search(dataset='LANDSAT_8_C1',
node='EE',
latitude=38.9072,
longitude=-77.0369,
start_date='2022-01-01',
end_date='2022-02-01')
# Print the result to see the available images
print(result)
As a note I have removed my login so that is not the issue. When I go to run this code I get the following error:
Traceback (most recent call last):
File "c:\Users\edwar\OneDrive\Research\MyCode\connect.py", line 13, in <module>
result = api.search(dataset='LANDSAT_8_C1',
^^^^^^^^^^
AttributeError: module 'usgs.api' has no attribute 'search'
I have looked up this error and read through the documentation however maybe I am missing something that someone can point out for me? I also have an API key is there something I need to do with that or is the login credientials enough?
I have gotten my idea to use api.search from here . This documentation does the same thing I have it is just formatted differently but the methods are the same.

Shodan - Python Syntax to use "Info" Tag

So I'm currently working on a script using Shodan in Python using import shodan.
The documentation around isn't the best so id thought I'd bring my issue here.
Using the Shodan CLI there is a command known as Shodan Info which displays the number of search credits that your account has remaining.
When looking at the Shodan Documentation i can see that there is an info() tag but whenever I use it there has been an error.
Does anyone know the correct syntax for using info in a python script to display the number of credits an account has?
Errors i have received:
ipinfo = shodan.info()
print (ipinfo)
Error
Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XX Documents/XXXX/Working
Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.info()
AttributeError: module 'shodan' has no attribute 'info'
And
ipinfo = shodan.Shodan(info())
print (ipinfo)
Error
Traceback (most recent call last):
File "C:/Users/XXXX/OneDrive - XXXX/Documents/XXXXDocuments/XXXXXX/Working
Segments/ShodanScraper.py", line 8, in <module>
ipinfo = shodan.Shodan(info())
NameError: name 'info' is not defined
You need to instantiate the Shodan class and then you will be able to use its Shodan.info() method. Here is how it looks in the official command-line interface:
https://github.com/achillean/shodan-python/blob/master/shodan/__main__.py#L364
Here's a short script that prints the current account usage information:
import pprint
import shodan
key = 'YOUR API KEY'
api = shodan.Shodan(key)
results = api.info()
pprint.pprint(results)
shodan does not express how to use info. heres a breif example of how to set up shodan info
import shodan
api = shodan.Shodan('YOUR API KEY')
info = api.host('8.8.8.8')
shodan info

Python script to get all private repos from an org/user

I'm on a mac and I'm trying to run a python script to get all the private repos from my organization/employees. Here's what I have so far:
import github3
gh = github3.login("username", "personal_access_taken")
org = gh.organization("org_name")
repos = list(org.iter_repos(type="private"))
print(repos)
Just an FYI, I'm new to python and API. Just started a few hours ago so I'm a complete newbie to this. I ran it and get back:
Traceback (most recent call last):
File "repo.py", line 4, in <module>
org = gh.organization("org_name")
File "/Users/user/Library/Python/2.7/lib/python/site-packages/github3/github.py", line 1566, in organization
json = self._json(self._get(url), 200)
File "/Users/user/Library/Python/2.7/lib/python/site-packages/github3/models.py", line 156, in _json
raise exceptions.error_for(response)
github3.exceptions.NotFoundError: 404 Not Found
What should I change to my script to make it work? Also, if I need to change to an employee would i replace org = gh.organization("org_name") with user = gh.user("employee_name)?
I tried your code and it works for me.
Make sure that you entered the correct organization name and that your user has access to this organization:
org = gh.organization("org_name")
You also should replace deprecated iter_repos() to repositories() method:
repos = list(org.repositories())

'Check' object has no attribute 'image' while using sightengine api

I am using sightengine API to detect child sexual abuse in images. In order to do that I am trying to detect the nudity level in an image using sightengine API. The following example is provided in the documentation itself.
from sightengine.client import SightengineClient
client = SightengineClient('api_user', 'api_key')
output = client.check('nudity').image('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
Apart from copying the same code I am getting the following error.
Traceback (most recent call last):
File "driver.py", line 3, in <module>
output = client.check('nudity').image('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
AttributeError: 'Check' object has no attribute 'image'
I have used both Python 2 and Python 3 for the same code but both raise the same error.
Try This:
from sightengine.client import SightengineClient
client = SightengineClient('API user', 'API secret')
checkNudity = client.check('nudity')
output1 = checkNudity.set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg')
print(output1)

how to access Flickr API using Python?

I installed everything as it says on the FlickrAPI homepage but when I try to run:
import flickrapi
api_key = '1a4c975fa83048436a2086bcab7d2290'
api_password = '5e069eae20e60297'
flickrclient = flickrapi.FlickAPI(api_key, api_password)
favourites = flickrClient.favorites_getPublicList(user_id='userid')
photos = flickr.photos_search(user_id='73509078#N00', per_page='10')
sets = flickr.photosets_getList(user_id='73509078#N00')
for photo in favourites.photos[0].photo:
print photo['title']
I get this message from the command prompt:
C:\Users\Desktop>python api.py
Traceback (most recent call last):
File "api.py", line 4, in <module>
flickrclient = flickrapi.FlickAPI(api_key, api_password)
AttributeError: 'module' object has no attribute 'FlickAPI'
Any ideas?? I have tried almost everything
FlickAPI is not the same as FlickrAPI. You're missing an r.
The file C:\Users\XXXXXX\Desktop\FLICKR API\flickrapi.py is not part of the flickrapi package. Please rename it, it is masking the real library. Right now it is being imported instead of the installed package.
The flickrapi package itself consists of a directory with a __init__.py file inside of it. Printing flickrapi.__file__ should result in a path ending in flickrapi\__init__.py.
In your "flickrclient = flickrapi.FlickAPI" line, you're missing an 'r' in FlickAPI.
Also, on the next line, your *"user_id='userid'"* argument needs an actual user ID, such as '999999#N99'
Hopefully you found that & got this working a few months ago! :)

Categories