小编edv*_*nch的帖子

为什么 raise_for_status() 没有捕捉到错误?

尝试在 current_track() 函数中检查无 200 响应。有什么问题?它抛出 JSONDecodeError 错误。但是,如果我正确理解 raise_for_ status ,它应该阻止该函数尝试从错误的网页加载 JSON 吗?如果我在没有此检查的情况下运行脚本并且使用取消注释行 check_playback() 它将成功捕获 JSONDecodeError。

该脚本正在从 Spotify 获取数据并将其置于 vk.com 上的状态。

import config
import webbrowser
import requests
import furl
import secrets
import string
import time
import os
import simplejson as json


URL_CODE_BASE_VK = 'https://oauth.vk.com/authorize'
URL_CODE_BASE_SP = 'https://accounts.spotify.com/authorize'
URL_TOKEN_VK = 'https://oauth.vk.com/access_token'
URL_TOKEN_SP = 'https://accounts.spotify.com/api/token'
URL_TRACK = 'https://api.spotify.com/v1/me/player/currently-playing'
URL_STATUS = 'https://api.vk.com/method/status.set'
EXP_IN_TOKEN_SP = 3400
EXP_IN_TOKEN_VK = 86400
FILE_TOKEN_VK = 'vk_token.json'
FILE_TOKEN_SP = 'sp_token.json'


def get_auth_code_vk():
    url_code_params = {
                        'client_id': config.CLIENT_ID_VK,
                        'response_type': 'code',
                        'redirect_uri': …
Run Code Online (Sandbox Code Playgroud)

python api-design spotify python-3.x python-requests

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