微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

给出 ParseError

如何解决给出 ParseError

如果用户活动的开始或/和结束日期时间发生变化,我正在尝试使用谷歌推送通知通知日历。

我已按照 push doc 中有关注册和验证我的域的所有步骤进行操作。

我的代码如下:

@blueprint.route("/notifications",methods={'GET','POST'})
def timeBlocker():
    email = '....@gmail.com'
    user = User.query.filter_by(email=email).first()  
    thecredentials = { 
    'client_id': os.getenv('client_id'),'client_secret':os.getenv('client_secret'),'refresh_token':user.refresh,'grant_type': 'refresh_token',}
    req = requests.post(url='https://oauth2.googleapis.com/token',data = thecredentials) 
    req_ = req.json()
    accesstoken = req_["access_token"]
    print('access token is ' + accesstoken)
    body = {
        'id': '01234567-89ab-cdef-0123456789ab','type': 'web_hook','address': 'https://dayliii.com/notifications'
    }
    headers = {'Authorization': 'Bearer ' + accesstoken,'Content-Type': 'application/json'
               }
    calendar = '....@group.calendar.google.com'
    req = requests.post(url='https://www.googleapis.com/calendar/v3/calendars/....@group.calendar.google.com/events/watch',data = body,headers=headers) 
    return str(req.json())

错误

{'error': {'errors': [{'domain': 'global','reason': 'parseError','message': 'Parse Error'}],'code': 400,'message ': '解析错误'}}

我尝试将双引号转换为单引号作为 similar post suggested 但它没有用。

最后,我很想知道在开发模式下处理推送通知时是否应该注册和验证“http://localhost:5000/”的域所有权?因为这是我期望得到的错误,不确定它的解决方法

解决方法

request() 函数中的 data 参数接受 json 格式。

您可以尝试使用 json.dumps() 将 body 变量转换为 json 字符串。

您的请求代码应如下所示:

req = requests.post(url='https://www.googleapis.com/calendar/v3/calendars/....@group.calendar.google.com/events/watch',data = json.dumps(body),headers=headers) 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。