Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:bitly请求_Python_Json - Fatal编程技术网

Python:bitly请求

Python:bitly请求,python,json,Python,Json,我正在尝试做一个基本的稍微缩短的URL调用。然而,我似乎既不能正确地推送json,也不能正确地处理json响应。。。为了简洁起见,我省略了一些明显的变量,为了安全起见,我混淆了一些实际值 import requests import json bitly_header = {'Authorization':'Bearer some_long_secret_character_string_here', 'Content-Type':'application/js

我正在尝试做一个基本的稍微缩短的URL调用。然而,我似乎既不能正确地推送json,也不能正确地处理json响应。。。为了简洁起见,我省略了一些明显的变量,为了安全起见,我混淆了一些实际值

import requests
import json
bitly_header = {'Authorization':'Bearer 
                some_long_secret_character_string_here', 'Content-Type':'application/json'}

bitly_data = {
        "long_url": ""+long_url+"",
        "group_guid": ""+bitly_guid+""
       }
short_link_resp =requests.post(bitly_endpoint,data=bitly_data,headers=bitly_header)
short_link_json = short_link_resp.json()
short_link = short_link_json["link"]
错误是“关键错误:链接”

我从邮递员那里得到的json是:

{
    "created_at": "1970-01-01T00:00:00+0000",
    "id": "bit.ly/2MjdrrG",
    "link": "bit.ly/2MjdrrG",
    "custom_bitlinks": [],
    "long_url": "google.com/",
    "archived": false,
    "tags": [],
    "deeplinks": [],
    "references": {
        "group": "https://api-ssl.bitly.com/v4/groups/Bi7i8IbM1x9"
    }
}

尝试将
数据
替换为
json

short_link_resp =requests.post(bitly_endpoint, json=bitly_data, headers=bitly_header)

请参阅。

尝试将
数据
替换为
json
。谢谢,问题解决了!现在-如何将您的帖子标记为“答案”?