python+requests中data的写法

错误写法

data ={
            "anchor_user_id": 922442,
            "token": "4a4fdd9f125aa594bb1024c2ce12e404",
             "user_id": 15896319
        }
 接口报错1007   print data发现双引号变单引号

在这里插入图片描述

解法一:data用’’’ ‘’'包围


```python
data ='''{
    "anchor_user_id": 922442,
    "token": "4a4fdd9f125aa594bb1024c2ce12e404",
     "user_id": 15896319
}'''

在这里插入图片描述
解法二:’’’{}’’'中需要传变量时,
变量string,则%s
变量int,则%d


```python
ts = calendar.timegm(time.gmtime())
vid = xxxx
data ='''{
    "time": %s,
     "visitor_id": %d
}'''%(ts,vid)

解法三:json.dumps(data)

  ts = calendar.timegm(time.gmtime())
  vid = xxxx
  data = {
            "anchor_user_id": 922442,
            "time": ts,
            "visitor_id": vid
        }
        json_str=json.dumps(data)

版权声明:本文为qq_34495095原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。