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())
Related
I'm trying to upload a video to Youtube using a python script.
So the code given here (upload_video.py) is supposed to work and I've followed the set up which includes enabling the Youtube API and getting OAuth secret keys and what not. You may notice that the code is in Python 2 so I used 2to3 to make it run with python3.7. The issue is that for some reason, I'm asked to login when I execute upload_video.py:
Now this should not be occuring as that's the whole point of having a client_secrets.json file, that you don't need to explicitly login. So once I exit this in-shell browser, Here's what I see:
Here's the first line:
/usr/lib/python3.7/site-packages/oauth2client/_helpers.py:255: UserWarning: Cannot access upload_video.py-oauth2.json: No such file or directory
warnings.warn(_MISSING_FILE_MESSAGE.format(filename))
Now I don't understand why upload_video.py-oauth2.json is needed as in the upload_video.py file, the oauth2 secret file is set as "client_secrets.json".
Anyways, I created the file upload_video.py-oauth2.json and copied the contents of client_secrets.json to it. I didn't get the weird login then but I got another error:
Traceback (most recent call last):
File "upload_video.py", line 177, in <module>
youtube = get_authenticated_service(args)
File "upload_video.py", line 80, in get_authenticated_service
credentials = storage.get()
File "/usr/lib/python3.7/site-packages/oauth2client/client.py", line 407, in get
return self.locked_get()
File "/usr/lib/python3.7/site-packages/oauth2client/file.py", line 54, in locked_get
credentials = client.Credentials.new_from_json(content)
File "/usr/lib/python3.7/site-packages/oauth2client/client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'
So basically now I've hit a dead end. Any ideas about what to do now?
See the code of function get_authenticated_service in upload_video.py: you should not create the file upload_video.py-oauth2.json by yourself! This file is created upon the completion of the OAuth2 flow via the call to run_flow within get_authenticated_service.
Also you may read the doc OAuth 2.0 for Mobile & Desktop Apps for thorough info about the authorization flow on standalone computers.
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.
from a ubuntu machine I use beatbox python package to connect to SF and get the objects descriptions
but can't manage to get access to the ForecastingItems object.
I checked my privileges to access the object and I have full access as admin
the script I'm using is bellow, when I changed the object ForecastingItem with Account it does pull all the object fields.
#!/usr/bin/python
# coding=utf8
import beatbox
import pprint
import sys
import os
import datetime
sf_service = beatbox.PythonClient()
sf_service.login('email#hotmail.com', 'password$numbersletter')
desc_obj = sf_service.describeSObjects('ForecastingItem')
forcat_item = desc_obj[0]
forItem_fields = forcat_item.fields
for sf_field_key, sf_field_value in forItem_fields.items():
print sf_field_key
I heard that I should upgrade beatbox to something more than the version 21 to be able to access the ForecastingItem object so I tried apt-get update upgrade beatbox, but I still get the error :
Traceback (most recent call last):
File "./fields_associated_with_an_object.py", line 14, in <module>
desc_obj = sf_service.describeSObjects('ForecastingItem')
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/python_client.py", line 131, in describeSObjects
res = BaseClient.describeSObjects(self, sObjectTypes)
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/_beatbox.py", line 108, in describeSObjects
return DescribeSObjectsRequest(self.__serverUrl, self.sessionId, sObjectTypes).post(self.__conn)
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/_beatbox.py", line 332, in post
raise SoapFaultError(faultCode, faultString)
beatbox._beatbox.SoapFaultError: 'INVALID_TYPE' "INVALID_TYPE: sObject type 'ForecastingItem' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names."
Thanks in advance!
I am trying to use the Remote API in a local Client, following instructions given in Google documentation (https://developers.google.com/appengine/docs/python/tools/remoteapi).
I first tried from the Remote API shell, and everything is working fine. I can connect to my remote datastore and fetch data.
But when I run the following script, which is very similar to Google's example :
#!/opt/local/bin/python2.7
import sys
SDK_PATH = "/usr/local/google_appengine/"
sys.path.append(SDK_PATH)
import dev_appserver
dev_appserver.fix_sys_path()
from google.appengine.ext.remote_api import remote_api_stub
import model.account
def auth_func():
return ('myaccount', 'mypasswd')
remote_api_stub.ConfigureRemoteApi('myappid', '/_ah/remote_api', auth_func)
# Fetch some data
entries = model.account.list()
for a in entries:
print a.name
then I get an error :
Traceback (most recent call last):
File "./remote_script_test.py", line 26, in <module>
entries = model.account.list()
[...]
File "/Developer/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/datastore/datastore_rpc.py", line 1333, in check_rpc_success
raise _ToDatastoreError(err)
google.appengine.api.datastore_errors.BadRequestError: Application Id (app) format is invalid: '_'
It says my application ID is a plain underscore '_', which is not the case since my app.yaml is correctly configured and when I do a
print app_identity.get_application_id()
from that script I get the correct application ID. I am under the impression that the GAE environment is not properly setup, but I could not figure out how to make it work. Does anyone have a full piece of code that works in this context ?
I am using Mac Os X Mountain Lion.
You may wish to start with remote_api_shell.py and remove stuff until it breaks, rather than add in things until it works.
For instance there's a line after the one you copied: remote_api_stub.MaybeInvokeAuthentication() is that necessary? There may be a number of necessary lines in remote_api_shell.py, maybe better to customize that rather than start from scratch.
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! :)