Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取所有github用户的详细信息_Python_Github_Github Api_Github3.py - Fatal编程技术网

Python 获取所有github用户的详细信息

Python 获取所有github用户的详细信息,python,github,github-api,github3.py,Python,Github,Github Api,Github3.py,我想获取github用户及其位置。我知道有一个githubapi(GET/users)可以为我提供用户列表。目前我正在使用它访问github,但是这个库似乎还没有实现这个API。有谁能建议我如何使用github API库获取github用户及其位置 编辑1: 我更新了代码,如下所示。但有些人认为我无法获得电子邮件Id和位置 import github3 from datetime import datetime def main(): g = github3.login(use

我想获取github用户及其位置。我知道有一个githubapi(GET/users)可以为我提供用户列表。目前我正在使用它访问github,但是这个库似乎还没有实现这个API。有谁能建议我如何使用github API库获取github用户及其位置

编辑1: 我更新了代码,如下所示。但有些人认为我无法获得电子邮件Id和位置

import github3
from datetime import datetime

def main():
        g = github3.login(username="rakeshcusat", password="mypassword")
    for user in g.iter_emails():
        print user
    current_time = datetime.now()   
    fhandler = open("githubuser_"+current_time.strftime("%d-%m-%y-%H:%M:%S"), "w")

    for user in g.iter_all_users():
            fhandler.write(" user: {0}, email: {1}, location: {2}\n".format(user, user.email, user.location))
            #fhandler.flush()

    fhandler.close()        

if __name__ == "__main__":
    main()
样本输出

 user: andywatts, email: None, location: 
 user: mueller, email: None, location: 
 user: cp, email: None, location: 
 user: davea, email: None, location: 
 user: vrieskist, email: None, location: 
支持对所有用户进行迭代:

import github3

for user in github3.iter_all_users():
    user.refresh()
    print user.location
生产

您需要在此处调用
.refresh()
,因为只返回较小的用户信息子集,而位置不包括在其中。这需要另一个API请求,因此您可能希望调整脚本的速度以避免达到GitHub速率限制

未来版本的
github3
(比0.7.0更新)添加了指定页面(批处理)大小的支持,以减少需要进行的API请求数量;GitHub API默认为每页30个结果,但您可以:


谢谢你的回复。我曾多次使用此库,但收到以下错误“github3.models.GitHubError:403超出了XYZ.XYZ.XYZ.XYZ的API速率限制”。你知道如何解决这个问题吗?你的ip地址达到了速率限制,请参阅。如果您先登录,将允许您提出更多请求。感谢您的宝贵意见。现在我登录并尝试,一切都在继续。希望这次它能下载列表。还有一个后续问题,我如何获得用户的电子邮件id。user.email有效吗?@Rakesh首先,我忘了他们只提供了用户的少量信息。可以对该用户对象调用refresh方法来获取所有内容,但这是另一个API调用。此外,很多用户没有设置他们的位置。
for user in github3.iter_all_users(per_page=100):
    user.refresh()
    print user.location