We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8dc90fb commit a3f2581Copy full SHA for a3f2581
.learn/resets/11-get-attachment-by-id/app.py
@@ -0,0 +1,7 @@
1
+import requests
2
+
3
+def get_attachment_by_id(attachment_id):
4
+ # Your code here
5
+ return None
6
7
+print(get_attachment_by_id(137))
.learn/resets/12-post-request/app.py
@@ -0,0 +1,3 @@
+# Your code here
.learn/resets/13-post-request-body/app.py
@@ -0,0 +1,4 @@
+response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
+print(response.text)
exercises/10-get-post-tags/app.py
@@ -1,8 +1,20 @@
import requests
def get_post_tags(post_id):
- # Your code here
- return None
+ url = "https://assets.breatheco.de/apis/fake/sample/weird_portfolio.php"
+ response = requests.get(url)
8
+ if response.status_code == 200:
9
+ data = response.json()
10
11
+ for post in data["posts"]:
12
+ if post["id"] == post_id:
13
+ return post["tags"]
14
+ print("No post found")
15
16
+ else:
17
+ print("Failed to fetch data from the endpoint.")
18
19
20
print(get_post_tags(146))
exercises/11-get-attachment-by-id/app.py
@@ -1,7 +1,21 @@
def get_attachment_by_id(attachment_id):
+ if "attachments" in post:
+ for attachment in post['attachments']:
+ if attachment['id'] == attachment_id:
+ return attachment['title']
+ print("No attachment found")
21
print(get_attachment_by_id(137))
exercises/12-post-request/app.py
@@ -1,3 +1,8 @@
-# Your code here
+url = 'https://assets.breatheco.de/apis/fake/sample/post.php'
+myobj = {'somekey': 'somevalue'}
+x = requests.post(url, json = myobj)
+print(x.text)
exercises/13-post-request-body/app.py
@@ -1,4 +1,9 @@
-response = requests.post("https://assets.breatheco.de/apis/fake/sample/save-project-json.php")
-print(response.text)
+url = 'https://assets.breatheco.de/apis/fake/sample/save-project-json.php'
+myobj = {"id": 2323,"title": "Very big project"}
+headers = {"Content-Type": "application/json"}
+x = requests.post(url, json = myobj, headers=headers)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments