how to access Flickr API using Python? - 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! :)

Related

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())

Python 3.4.3 save image from url to file using urllib

I tried to make a python program that would allow me to download a jpg file from a website.
Why I'm doing this is really for no reason at all, I just wanted to try it for fun.
Anyways, here is the code:
import urllib
a = 1
while a == 1:
urllib.urlretrieve("http://lemerg.com/data/wallpapers/38/957049.jpg","D:\\Users\\Elias\\Desktop\\FolderName-957049.jpg")
(You may have to properly tab it in, it wouldn't let me here)
So basically what I want it to do is to repeatedly download the same file until I close the program. Just don't ask why.
The error code I get is:
Traceback (most recent call last):
urllib.urlretrieve("http://lemerg.com/data/wallpapers/38/957049.jpg","D:\Users\Elias\Desktop\FolderName-957049.jpg")
AttributeError: 'module' object has no attribute 'urlretrieve'
urlretrieve() in Python3 is in the urllib.request module. Do this:
from urllib import request
a = 1
while a == 1:
request.urlretrieve("http://lemerg.com/data/wallpapers/38/957049.jpg","D:\\Users\\Elias\\Desktop\\FolderName-957049.jpg")

Using google_rest API

I am trying to use the Google Drive API to download publicly available files however whenever I try to proceed I get an import error.
For reference, I have successfully set up the OAuth2 such that I have a client id as well as a client secret , and a redirect url however when I try setting it up I get an error saying the object has no attribute urllen
>>> from apiclient.discovery import build
>>> from oauth2client.client import OAuth2WebServerFlow
>>> flow = OAuth2WebServerFlow(client_id='not_showing_client_id', client_secret='not_showing_secret_id', scope='https://www.googleapis.com/auth/drive', redirect_uri='https://www.example.com/oauth2callback')
>>> auth_uri = flow.step1_get_authorize_url()
>>> code = '4/E4h7XYQXXbVNMfOqA5QzF-7gGMagHSWm__KIH6GSSU4#'
>>> credentials = flow.step2_exchange(code)
And then I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line
137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line
1980, in step2_exchange
body = urllib.parse.urlencode(post_data)
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute
'urlencode'
Any help would be appreciated, also would someone mind enlightening me as to how I instantiate a drive_file because according to https://developers.google.com/drive/web/manage-downloads, I need to instantiate one and I am unsure of how to do so.
Edit: So I figured out why I was getting the error I got before. If anyone else is having the same problem then try running.
sudo pip install -I google-api-python-client==1.3.2
However I am still unclear about the drive instance so any help with that would be appreciated.
Edit 2: Okay so I figured out the answer to my whole question. The drive instance is just the metadata which results when we use the API to search for a file based on its id
So as I said in my edits try the sudo pip install and a file instance is just a dictionary of meta data.

NameError: name 'TigerXtrm' is not defined

I'm in the process of installing a piece of software from Github: https://github.com/bravecollective/core
It uses MongoDB, Python and WebCore to run. I've managed to get it running and now I've arrived at the part where I need to make myself an admin user. According to the readme, the following needs to be executed in the Paster shell.
from brave.core.account.model import User
from brave.core.character.model import EVECharacter
from brave.core.permission.model import Permission, WildcardPermission
u = User.objects(username=USERNAME_HERE)[0]
u.admin = True
c = u.primary
p1 = Permission.objects(id='core.*').first()
c.personal_permissions.append(p1)
c.save()
u.save()
The username in this case being 'TigerXtrm'. However, when I do this it comes back with the following:
Welcome to the WebCore shell.
from brave.core.account.model import User
from brave.core.character.model import EVECharacter
from brave.core.permission.model import Permission, WildcardPermission
u = User.objects(username=TigerXtrm)[0]
c = u.primary
p1 = Permission.objects(id='core.*').first()
c.personal_permissions.append(p1)
Traceback (most recent call last):
File "console", line 1, in module
NameError: name 'TigerXtrm' is not defined
So NameError: name 'TigerXtrm' is not defined is what creates a problem for me. The user is created and has been entered into the MongoDB database, I've also tried lowercase and e-mail adress, both to no avail. I can't figure out why it's telling me it's not defined. Am I executing it in the wrong place or is there something wrong with the code? Or something else entirely?
That's the Python interpreter complaining because you need to quote TigerXtrm:
u = User.objects(username="TigerXtrm")[0]

python twitter Api() not found error

I'm trying to use the python-twitter module, but still having problems initiating the twitter.Api(). I've checked and rechecked that no other file named twitter.py or twitter.pyc is on my system. On a clean install i first try to
>>> import twitter
and correctly get a response of 'module unknown'
I do a easy_install twitter, successfull.
Then do
>>> import twitter
>>> testapi = twitter.Api()
The response is
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
testapi = twitter.Api()
AttributeError: 'module' object has no attribute 'Api'
>>>
I'm exhausted trying to locate the problem here, please help.
It appears that you are trying to follow the documentation for one Python Twitter module when you are in fact using another Python Twitter module.
The Api() method call you mention is part of this Python Twitter module. However, when you use easy_install twitter, you actually get this other Python Twitter module.

Categories