Skip to content

Instantly share code, notes, and snippets.

@royshan
Created January 4, 2013 13:04
Show Gist options
  • Save royshan/4452481 to your computer and use it in GitHub Desktop.
Save royshan/4452481 to your computer and use it in GitHub Desktop.
a dnspod dynamic dns update script
#!/usr/local/bin/python2.7
#-*- coding:utf-8 -*-
import requests
params = dict(
login_email='youremail@xyz.com',
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()
@royshan
Copy link
Author

royshan commented Jan 4, 2013

@mrluanma 谢谢指正!明天测一下。

@mrluanma
Copy link

mrluanma commented Jan 4, 2013

@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