I was calling github api from my python scripts. if run successfully, it would have made around 3000 calls. However, after 50-60 successful calls, it shows the below message-
{'message': "API rate limit exceeded for 108.169.151.47. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", 'documentation_url': 'https://developer.github.com/v3/#rate-limiting'}
I have read the documentation. I don't have any application to register with to get a client id and client secret.
From my github account, I generated a token. I'm wondering if I can use that to send authenticated requests.
I tried some curl command to log in through my github profile in the git bash, and then run the python script, but it still shows the same message.
Can you suggest a way how can I make use of the good news in the message?
You might want to consider just using basic authentication with your GitHub username and password. The response received should be converted to JSON.
req = requests.get(url, auth=(USERNAME, PASSWORD))
req_json = req.json()
Related
I am trying to login to my reddit account using python, not Praw. I succufully extracted the CSRF token, but still don't know why it is not functional and unable to properly login. The desired behavior of the code is to be able to login to reddit through this python script and then confirm if the logging was a success or not.
When you try to login on your browser, in the developer tools (Network tab) you can preview how the request should look. The mistake you made here is that the POST request should be sent not to: https://www.reddit.com/, but https://www.reddit.com/login.
To verify the result you can check, in the debugger, the response you received to your POST request. When I ran your code with the mentioned change of URL the response to "r" was: response
You can see that the server returned response status code 400 with explanation "incorrect username or password". It means that your code should be enough to login to Reddit with inputting the correct credentials.
I have been recently reading about the Twitch API reference to figure out getting channel ids by username, but have no idea how to use it. https://api.twitch.tv/helix/users is the link where I was sending my params.
URL = "https://api.twitch.tv/helix/users"
channelName = {'OAuth': os.environ["Oauth"]}
r = requests.get(url=URL, params=channelName)
print(r.text)
Message:
{"error":"Unauthorized","status":401,"message":"OAuth token is missing"}
I provided the token so I don't know where I went wrong. Any ideas?
Through the API itself you would use the twitch login name with
GET https://api.twitch.tv/helix/users?login=<login name>&login=<login name>
With the return values you can acquire the ID.
You can find the query and response information at
https://dev.twitch.tv/docs/api/reference#get-users
Though the error you're seeing means you haven't generated or setup a token required to make these requests from the Twitch API. You need to make sure you're going through the setup process and utilizing the client-ID and Oath token to make your requests.
More information on how to get started: https://dev.twitch.tv/docs/api#step-1-setup
I'm trying to learn the requests library in python and I'm following a guide. I'm sending a get request to api.github.com/user but I keep on getting a Status Code of 401. For username, I was using my email at first, but I thought that was what was making it fail so I changed it to my GitHub username and it still doesn't work. Is there anything I'm doing wrong or are there solutions?
import requests
from getpass import getpass
response = requests.get(
"https://api.github.com/user",
auth=('username', getpass())
)
print(response)
You can no longer authenticate to the GitHub API using Basic authentication (a username and password). That ability has been removed. This API endpoint requires authentication because it tells you the current user, and when you're not logged in, there is no current user.
You'll need to generate a personal access token with the appropriate scopes and use it to authenticate to the API instead. You can also use an OAuth token if you're using an OAuth app, but it doesn't sound like you need that in this case.
I'm trying to call Github APIs to the Github Enterprise Server in the company that I work for. The API calls works when I use personal access token, but every time I used user name and password, I'm getting an HTTP 401 error message "Must authenticate to use this API".
I tried using the following tools:
curl
Sample call:
curl --proxy $PROXY -i --user "xx-xx" https://github.xxx.xxx.com/api/v3/users
PyGithub
Sample code:
gh = Github('my-user', password='....', base_url='https://github.xxx.xxx.com/api/v3/users')
Python requests API
Sample code
r = requests.get('https://github.xxx.xxx.com', auth=('my-user','....'), proxies=proxyDict)
Doesn't work if I use either HTTPBasicAuth or HTTPDigestAuth
The company github website is authenticated via SAML, so I'm wondering if this is SAML related issue.
Github does not allow http/https authentications. (same for bitbucket and gitlab). I learnt it hard-way.
You may want to use ssh public key based authentication.
Github API supports Basic Authentication as defined in RFC2617 with a few small differences.
cURL example:
curl -u username https://api.github.com/user
cURL will prompt you to enter the password.
PyGitHub example:
g = Github("user", "password")
for repo in g.get_user().get_repos():
print(repo.name)
Requests example:
response = requests.get('https://api.github.com/user', auth=('username', 'password'))
I would suggest using PyGitHub instead of Requests. And also Postman which is a nice cURL alternative to try things out.
I have a Google App Engine Python application that interacts with a JIRA Cloud instance.
To date the application makes urlfetch calls to JIRA using Basic Authentication but as it is now making dozens of separate REST calls both POST and GET I was hoping that using cookie authentication would reduce the latency somewhat.
example Basic-Authentication code that works:
result = urlfetch.fetch(jira_url,
deadline=60,
headers={"Authorization": "Basic %s" %
base64.b64encode("%s:%s" % (username, password))
})
and cookie alternative:
result = urlfetch.fetch(jira_url,
deadline=60,
headers={"X-Atlassian-Token": "no-check",
"Cookie": "JSESSIONID=529…snip…C4C"
})
I retrieved the JSESSIONID successfully using the instructions but the cookie query will only return "401 - Unauthorized" error while loading this page. errors as if the cookie has expired.
{
"errorMessages" : [
"You do not have the permission to see the specified issue.",
"Login Required"
],
"errors" : {}
}
I am recalling the cookie from Memcache as most of the interactions are made from a Task Queue and necessarily a separate thread, but the cookie is generated immediately before the recall.
The cookie is not expired. The cause of the issue is that JSESSIONID is not the only cookie which is required for the successful authentication of subsequent requests.
I encountered the same issue and solved it by re-sending all cookies I got from the server when creating the session. In my case (the JIRA server is hosted at Atlassian Cloud) these required cookies are: atlassian.xsrf.token and studio.crowd.tokenkey.
I posted a detailed article on this here: JIRA REST API: Cookie-based Authentication. The example of the code is in C# but the general idea should be clear.