小编aes*_*tux的帖子

Google Shortener API和Python出错

我正在制作一个与网址一起使用的应用程序,我需要缩短它们.我写了以下代码:

import requests, json
gUrl = 'https://www.googleapis.com/urlshortener/v1/url'
data = json.dumps({'longUrl': 'http://www.google.es'})
r = requests.post(gUrl, data)
Run Code Online (Sandbox Code Playgroud)

它应该用json编码,但是,我收到以下错误:

print r.json
{u'error': {u'code': 400, u'message': u'This API does not support parsing form-encoded
input.', u'errors': [{u'domain': u'global', u'message': u'This API does not support
parsing form-encoded input.', u'reason': u'parseError'}]}}
Run Code Online (Sandbox Code Playgroud)

其他可能有用的信息:

print r.request
Request [POST]


print r.headers
{'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff',
'transfer-encoding': 'chunked', 'expires': 'Thu, 05 Jul 2012 20:47:11 GMT',
'server': 'GSE', 'cache-control': 'private, max-age=0', 
'date': 'Thu, 05 Jul 2012 20:47:11 GMT', 'x-frame-options': 'SAMEORIGIN', 
'content-type': …
Run Code Online (Sandbox Code Playgroud)

python api json google-url-shortener

1
推荐指数
1
解决办法
2099
查看次数

标签 统计

api ×1

google-url-shortener ×1

json ×1

python ×1