1

I have the following code. I am trying to access to https://api.github.com/users/jtorre94 via the requests library.

import requests
api_url = "https://api.github.com/users"
response = requests.get(api_url, params={'login': 'jtorre94'})
response.json()

However, the response is something I do not recognize at all, like if it was not filtered by the jtorre94 parameter.

[{'login': 'mojombo',
  'id': 1,
  'node_id': 'MDQ6VXNlcjE=',
  'avatar_url': 'https://avatars.githubusercontent.com/u/1?v=4',
  'gravatar_id': '',
  'url': 'https://api.github.com/users/mojombo',
  'html_url': 'https://github.com/mojombo',
  'followers_url': 'https://api.github.com/users/mojombo/followers',
  'following_url': 'https://api.github.com/users/mojombo/following{/other_user}',
  'gists_url': 'https://api.github.com/users/mojombo/gists{/gist_id}',
  'starred_url': 'https://api.github.com/users/mojombo/starred{/owner}{/repo}',
  'subscriptions_url': 'https://api.github.com/users/mojombo/subscriptions',
  'organizations_url': 'https://api.github.com/users/mojombo/orgs',
  'repos_url': 'https://api.github.com/users/mojombo/repos',
  'events_url': 'https://api.github.com/users/mojombo/events{/privacy}',
  'received_events_url': 'https://api.github.com/users/mojombo/received_events',
  'type': 'User',
  'site_admin': False},
 {'login': 'defunkt',
  'id': 2,
  'node_id': 'MDQ6VXNlcjI=',
  'avatar_url': 'https://avatars.githubusercontent.com/u/2?v=4',
  'gravatar_id': '',
  'url': 'https://api.github.com/users/defunkt',
  'html_url': 'https://github.com/defunkt',
  'followers_url': 'https://api.github.com/users/defunkt/followers',
  'following_url': 'https://api.github.com/users/defunkt/following{/...

How can I retrieve the json for username jtorre94?

1 Answer 1

3

Append it to the url as you already tried with your browser:

import requests
user = 'jtorre94'
api_url = f"https://api.github.com/users/{user}"
response = requests.get(api_url)
response.json()

Output:

{'login': 'jtorre94',
 'id': 76944588,
 'node_id': 'MDQ6VXNlcjc2OTQ0NTg4',
 'avatar_url': 'https://avatars.githubusercontent.com/u/76944588?v=4',
 'gravatar_id': '',
 'url': 'https://api.github.com/users/jtorre94',
 'html_url': 'https://github.com/jtorre94',
 'followers_url': 'https://api.github.com/users/jtorre94/followers',
 'following_url': 'https://api.github.com/users/jtorre94/following{/other_user}',
 'gists_url': 'https://api.github.com/users/jtorre94/gists{/gist_id}',
 'starred_url': 'https://api.github.com/users/jtorre94/starred{/owner}{/repo}',
 'subscriptions_url': 'https://api.github.com/users/jtorre94/subscriptions',
 'organizations_url': 'https://api.github.com/users/jtorre94/orgs',
 'repos_url': 'https://api.github.com/users/jtorre94/repos',
 'events_url': 'https://api.github.com/users/jtorre94/events{/privacy}',
 'received_events_url': 'https://api.github.com/users/jtorre94/received_events',
 'type': 'User',
 'site_admin': False,
 'name': None,
 'company': None,
 'blog': '',
 'location': None,
 'email': None,
 'hireable': None,
 'bio': None,
 'twitter_username': None,
 'public_repos': 4,
 'public_gists': 0,
 'followers': 0,
 'following': 0,
 'created_at': '2021-01-04T10:11:25Z',
 'updated_at': '2022-07-23T11:17:18Z'}
Sign up to request clarification or add additional context in comments.

2 Comments

What would be the use case then for passing params as an input?
@JaviTorre. There is no case to use parameters when you get a user. However if you want to retrieve some information about user, you have to specify the subject_type parameter (but you need an api key).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.