“Python基础API的调用”的版本间的差异
跳到导航
跳到搜索
(创建页面,内容为“ 一直在用 居然没注意到这个就叫api调用 =使用requests库发送GET请求= <pre> ➜ tmp cat gapi.sh import requests response = requests.get('https…”) |
|||
(未显示同一用户的2个中间版本) | |||
第3行: | 第3行: | ||
=使用requests库发送GET请求= | =使用requests库发送GET请求= | ||
<pre> | <pre> | ||
+ | 也有 requests.post | ||
+ | info = requests.post(url=webhook, data=message_json, headers=header).json() dingding机器人 | ||
➜ tmp cat gapi.sh | ➜ tmp cat gapi.sh | ||
import requests | import requests | ||
第20行: | 第22行: | ||
</pre> | </pre> | ||
+ | =references= | ||
+ | |||
+ | [https://docs.pingcode.com/baike/1277051 如何调用api接口python] | ||
[[category:python]] | [[category:python]] |
2024年10月23日 (三) 13:29的最新版本
一直在用 居然没注意到这个就叫api调用
使用requests库发送GET请求
也有 requests.post info = requests.post(url=webhook, data=message_json, headers=header).json() dingding机器人 ➜ tmp cat gapi.sh import requests response = requests.get('https://api.github.com/users/octocat') if response.status_code == 200: user_data = response.json() print(user_data) else: print("failed to retrieve data: {response.status_code}") ➜ tmp py3 gapi.sh {'login': 'octocat', 'id': 583231, 'node_id': 'MDQ6VXNlcjU4MzIzMQ==', 'avatar_url': 'https://avatars.githubusercontent.com/u/583231?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/octocat', 'html_url': 'https://github.com/octocat', 'followers_url': 'https://api.github.com/users/octocat/followers', 'following_url': 'https://api.github.com/users/octocat/following{/other_user}', 'gists_url': 'https://api.github.com/users/octocat/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/octocat/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/octocat/subscriptions', 'organizations_url': 'https://api.github.com/users/octocat/orgs', 'repos_url': 'https://api.github.com/users/octocat/repos', 'events_url': 'https://api.github.com/users/octocat/events{/privacy}', 'received_events_url': 'https://api.github.com/users/octocat/received_events', 'type': 'User', 'site_admin': False, 'name': 'The Octocat', 'company': '@github', 'blog': 'https://github.blog', 'location': 'San Francisco', 'email': None, 'hireable': None, 'bio': None, 'twitter_username': None, 'public_repos': 8, 'public_gists': 8, 'followers': 15135, 'following': 9, 'created_at': '2011-01-25T18:44:36Z', 'updated_at': '2024-09-22T11:25:27Z'} ➜ tmp