同步操作将从 编程语言算法集/Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
requests with httpx (#12744)
#!/usr/bin/env python3"""Created by sarathkaul on 14/11/19Updated by lawric1 on 24/11/20Authentication will be made via access token.To generate your personal access token visit https://github.com/settings/tokens.NOTE:Never hardcode any credential information in the code. Always use an environmentfile to store the private information and use the `os` module to get the informationduring runtime.Create a ".env" file in the root directory and write these two lines in that filewith your token::#!/usr/bin/env bashexport USER_TOKEN="""""# /// script# requires-python = ">=3.13"# dependencies = [# "httpx",# ]# ///from __future__ import annotationsimport osfrom typing import Anyimport httpxBASE_URL = "https://api.github.com"# https://docs.github.com/en/free-pro-team@latest/rest/reference/users#get-the-authenticated-userAUTHENTICATED_USER_ENDPOINT = BASE_URL + "/user"# https://github.com/settings/tokensUSER_TOKEN = os.environ.get("USER_TOKEN", "")def fetch_github_info(auth_token: str) -> dict[Any, Any]:"""Fetch GitHub info of a user using the httpx module"""headers = {"Authorization": f"token {auth_token}","Accept": "application/vnd.github.v3+json",}return httpx.get(AUTHENTICATED_USER_ENDPOINT, headers=headers, timeout=10).json()if __name__ == "__main__": # pragma: no coverif USER_TOKEN:for key, value in fetch_github_info(USER_TOKEN).items():print(f"{key}: {value}")else:raise ValueError("'USER_TOKEN' field cannot be empty.")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。