python用requests get(url)调用github的api提示 HTTPSConnectionPool

问题遇到的现象和发生背景

在练习《python编程 从入门到实践》一书的第17章时,我在调用GitHub的api时总是提示443错误,无论是挂代理还是使用devside car都不能解决问题

问题相关代码,请勿粘贴截图
import requests

url = 'https://api.githun.com/search/reppositories?q=language:python&sort=stars'
r = requests.get(url)

print('Status Code:', r.status_code)

response_dict = r.json()
print(response_dict.keys())
运行结果及报错内容
发生异常: ConnectionError
HTTPSConnectionPool(host='api.githun.com', port=443): Max retries exceeded with url: /search/reppositories?q=language:python&sort=stars (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001F03E0C52B0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

During handling of the above exception, another exception occurred:


During handling of the above exception, another exception occurred:


During handling of the above exception, another exception occurred:

  File "E:\BaiduNetdiskWorkspace\Python代码集合\书籍\Chapter_17\python_repos.py", line 5, in <module>
    r = requests.get(url)


由于其api中需要传入参数不一致,需要headers,有的需要token,对于topics可以用如下方式获取:

import requests

url = 'https://api.github.com/search/topics?q=python&sort=stars'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36 Edg/98.0.1108.43', 'content-type': 'application/json; charset=utf-8'}
r = requests.get(url,headers=headers)

print('Status Code:', r.status_code)

response_dict = r.json()
print(response_dict)

如有帮助,请点采纳。

由于目标计算机积极拒绝,无法连接。
书上提供的地址不一定能用,你可以用其他地址。
比如:

https://www.baidu.com/s
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632