質問編集履歴
1
APIでの変数の送信方法を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,6 +76,58 @@
|
|
76
76
|
|
77
77
|
```
|
78
78
|
|
79
|
+
### pythonでAPIにアクセスしようとしたコード
|
80
|
+
|
81
|
+
```python
|
82
|
+
|
83
|
+
import base64
|
84
|
+
|
85
|
+
import json
|
86
|
+
|
87
|
+
import urllib.request as request
|
88
|
+
|
89
|
+
from urllib.parse import urljoin
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
wp_url_api_cf = 'https://test.net/wp-json/wp/v2/posts/'
|
94
|
+
|
95
|
+
post_id = 99
|
96
|
+
|
97
|
+
wp_url_api_cf_post = urljoin(wp_url_api_cf,post_id)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
payload_cf = {'featured_media_from_external_url':'https://testgazou/test.jpg'}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
wp_user='ユーザー名'
|
106
|
+
|
107
|
+
wp_pass='アプリケーションパスワード'
|
108
|
+
|
109
|
+
basic_user_and_pasword = base64.b64encode('{}:{}'.format(wp_user, wp_pass).encode('utf-8'))
|
110
|
+
|
111
|
+
headers_cf={'Authorization': 'Basic {}'.format(basic_user_and_pasword.decode('utf-8'))}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
req_cf = request.Request(wp_url_api_cf_post,
|
116
|
+
|
117
|
+
json.dumps(payload_cf).encode(),
|
118
|
+
|
119
|
+
headers_cf,
|
120
|
+
|
121
|
+
method='PUT')
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
res_cf=request.urlopen(req_cf)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
130
|
+
|
79
131
|
|
80
132
|
|
81
133
|
### 試したこと
|