PyGitHub .RateLimitExceededException: 403 Authentication Trouble - python

I have been attempting to use PyGitHub to edit/update my repository files using PyGitHub, however (I guess I tried to access it too many times :P) it gives me this error:
github.GithubException.RateLimitExceededException: 403 {"message": "API rate limit exceeded for xx.xx.xx.xxxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", "documentation_url": "https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
I was accessing the data just fine before. I had researched it and in the effort to fix the problem I had replaced my username with an access token. Here is my full code:
from github import Github
# Github username
username = "JosephCWatkins"
password = yeoldepasswordhere
# pygithub object
g = Github(yeolaccesstokenhere, password)
user = g.get_user(username)
repof = g.get_repo("JosephCWatkins/moonspellprojectprogress")
#me trying to access the data :P:
contents = repof.get_contents("test.txt")
print(contents.content.split.__doc__())
It says that I must authenticate myself which would give me a higher rate limit, but the best I could figure out on trying to solve it was adding the access token. Am I doing something wrong? How can I authenticate myself so I can continue working with the API? And also, if you could help me be able to print the contents of a repository file. Thank You. :)

The first part of my question is still unanswered, but I accessed the contents of my GitHub Repository File with this code:
repo = g.get_repo("username/repositoryname")
contents = repo.get_contents("filename.filetype").decoded_content
I know it sounds simple but the documentation does not go into the various functions like it should, it mostly only gives examples. Plus the internet lacks a simple answer to this problem. For anyone who wants to access their GitHub file via PyGitHub, here it is.

Related

Updating clientStates in cloudidentity api failing

Following the guide in Google's documentation I am attempting to update fields for a device. This returns Permission denied. Did you provide the correct client id? which I have verified is absolutely the correct id.
If I log the error.msg I get HTTP Error 400: Bad Request, and looking at the contents I see that
<p>The requested URL <code>/v1/devices/abc123/deviceUsers/abc-123-ddd/clientState/companyid-string?updateMask=healthScore</code> was not found on this server. <ins>That\xe2\x80\x99s all we know.
I took the resource name from using the list method, as suggested by the docs, so I am fairly certain this is the correct name. I don't believe its a scope permission error as the scope listed works to list/get devices.
I have tried updating different fields, different devices, and switching it up as much as I could think to do and still run into a 400. If anyone has updated any of the clientState fields and can provide guidance I would greatly appreciate it.

How to send an email attachment over 4MB using Python & Microsoft Graph API

Been scrolling across the web including here on Stackoverflow and can't find an answer to my question so I was wondering if anyone knew how to help please. I am using Python and have managed to get the following code to work for my app. This app sends an email through my corporate O365 account. It works well, sends an email and have also made it works with small attachments (less than 4MB). Here it is:
from O365 import Account,MSGraphProtocol
client_ID = ''
secret = ''
credentials = (client_ID, secret)
protocol = MSGraphProtocol(api_version='beta')
account = Account(credentials,protocol=protocol)
m = account.new_message()
m.to.add('email#email.com')
m.subject = 'sCRIPT FOR AUTOMATION'
m.body = "This is a test!"
m.attachments.add('big_file.csv') #takes a list for multiple files. However, 4MB size limit.
m.send()
This is all well and good, however, I need it to work with larger attachments. I feel like I have tried everything I can think of to make it work, however, haven't had any success. I saw some documentation here that suggested changing the protocol to MsGraphProtocol & api version to beta (see https://pypi.org/project/O365/) which I tried without success. I have read a lot into this problem and it seems Microsoft is aware of it but they claim to have a solution which is to create an upload session and upload my larger file in chunks? I have no idea where to start with this. I tried looking at this documentation https://learn.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http and https://learn.microsoft.com/en-us/graph/api/attachment-createuploadsession?view=graph-rest-beta&tabs=http. However, none of this documentation was written for Python programmers, let alone beginners/intermediate users so got lost fairly quickly. I kind of get the problem. The request can't be bigger than 4MB and therefore I need to iterate my upload. I have an understanding of for loops in python, however, I haven't found it particularly clear how to apply this documentation to my particular use case. If someone could help/has done something like this before in Python, please let me know! Any help would be hugely appreciated. Thanks!
Adding code sample:
#!/usr/bin/python
print "GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var attachmentItem = new AttachmentItem{
AttachmentType = AttachmentType.File,
Name = \"flower\",
Size = 3483322 };
await graphClient.Me.Messages[\"AAMkADI5MAAIT3drCAAA=\"].Attachments
.CreateUploadSession(attachmentItem)
.Request()
.PostAsync();\n";

How do i properly authenticate to the github Api v3 using pyGithub. getting bad credentials error

I'm trying to use the Pygithub library for python to access my repositories through the github API v3. I'm following the tutorial given by the documentation and storing my credentials in another file called credentials. I checked to see that these were correctly loaded and they were. they're formatted as "user" and "password" so nothing else except my actual username and my actual pass.
this is the code
from github import Github
credentials = open("credentials")
user = credentials.readline()
Pass = credentials.readline()
clientId = credentials.readline()
credentials.close()
git = Github(user,Pass)
repos = [ _ for _ in git.get_user().get_repos()]
code error received
Is there anything else i should add to the user and password string? I don't get why I'm getting this error and i can't find anything about it in the docs or from other questions?
I solved it. I forgot to strip my credentials from their breaklines. which is why the API kept telling me bad credentials. A quick debug told me this. (stupid enough to have done this many times, instead of debugging i print the lines i receive but this doesn't print breaklines ofcourse)

API request to Yahoo using oAuth & Python

I've gotten the oAuth request working. I have the token back, and I'm able to get the signature and other variables necessary. However, I'm not exactly sure what to do with them to make the request for content. I've tried about a million different things, and none worked. So, here is what I have so far:
After authenticating with oAuth, I have the following variables:
{'oauth_body_hash': '2jmj7l5rS.....YBwk=', u'oauth_nonce':
u'05141181', u'oauth_timestamp': 1401657766, u'oauth_consumer_key':
u'dj0yJm.....meD1iMA--', 'oauth_signature_method': 'HMAC-SHA1',
u'oauth_version': u'1.0', u'oauth_token':
u'A=tdGQU1Pfrg......DhB6kbr40A--', 'oauth_signature':
'WUi69.....CyL2k='}
I think I should be doing something like the below, where headers = what is posted above.
from requests import request
r = request(method='GET', url="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20fantasysports.players%20where%20player_key%3D\'238.p.6619\'&format=json&callback=", headers=STRING_ABOVE)
However, I just keep getting the below message.
Authentication Error. The table fantasysports.players requires a higher security level than is provided, you provided ANY but at least USER is expected"
I'm not sure what to try next. Sorry about the beginner question. I'm sure this is simple stuff, but i'm still learning.

Trouble getting code parameter on facebook oauth callback

I'm writing a Django app requesting permission to post on facebook.
I can access authorization and callback, but I can't get the parameter 'code' that facebook needs to continue with oauth.
def connect_fb(request):
return redirect("https://graph.facebook.com/oauth/authorize?"
+"client_id=MY_ID&"
+"redirect_uri=MY_URL"
+"&type=user_agent&display=popup&scope=publish_stream")
def callback_facebook(request):
code=request.REQUEST.get("code")
What's the right way to get 'code' so I can continue the oauth process?
I tried several things but I keep getting None instead of a code.
Thanks
I've used django-facebook-oauth in the past, but if you really want to roll your own solution then I'd suggest just looking through their source.
From just glancing through it, the only thing I can see you doing differently is the
&type=user_agent&display=popup
in the URL. The app I linked you to doesn't appear to do that as far as I can tell.
The problem comes from type=user_agent that is used in javascript authentication, and not here.
Removing it allows to get code as above.

Categories