Created
January 4, 2013 13:04
-
-
Save royshan/4452481 to your computer and use it in GitHub Desktop.
a dnspod dynamic dns update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python2.7 | |
#-*- coding:utf-8 -*- | |
import requests | |
params = dict( | |
login_email='[email protected]', | |
login_password='your password', | |
format='json', | |
domain_id=123456, | |
record_id=133456, | |
sub_domain='your_sub_domain', | |
record_line='默认', | |
) | |
def ddns(): | |
headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/json'} | |
r = requests.post('https://dnsapi.cn/Record.Ddns', data=params, headers=headers) | |
ddns() |
mrluanma
commented
Jan 4, 2013
- requests默认会设置POST的Content-Type header为application/x-www-form-urlencoded。
- JSON的mimetype应该是application/json。
@mrluanma 谢谢指正!明天测一下。
@royshan 我刚才也确认了一下。准确说应该是requests在POST请求 && data参数是dict && Content-Type header没有设置的情况下会自动设置Content-Type header为application/x-www-form-urlencoded。
$ python -c 'import requests; print requests.post("https://httpbin.org/post", data={1: 2}).content'
{
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"Accept": "*/*",
"Connection": "keep-alive",
"Accept-Encoding": "gzip, deflate, compress",
"User-Agent": "python-requests/1.0.3 CPython/2.7.2 Darwin/12.2.0",
"Content-Length": "3"
},
"files": {},
"origin": "10.47.19.6",
"args": {},
"url": "http://httpbin.org/post",
"data": "",
"form": {
"1": "2"
},
"json": null
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment