我正在尝试学习如何使用YahooApi,但是当从网站获取数据时,它会给我一个内部服务器错误。我已经尝试了联盟或联赛数据甚至一般游戏数据的所有组合,但是一切都给了我一个内部服务器错误。我在下面附上了我的代码,我能收到的任何帮助都会非常有帮助。
import json
import time
import webbrowser
import pandas as pd
from pandas.io.json import json_normalize
from rauth import OAuth1Service
from rauth.utils import parse_utf8_qsl
credentials_file = open('auth.json')
credentials = json.load(credentials_file)
credentials_file.close()
oauth = OAuth1Service(consumer_key = 'key',
consumer_secret = 'secret',
name = "yahoo",
request_token_url = "https://api.login.yahoo.com/oauth/v2/get_request_token",
access_token_url = "https://api.login.yahoo.com/oauth/v2/get_token",
authorize_url = "https://api.login.yahoo.com/oauth/v2/request_auth",
base_url = "http://fantasysports.yahooapis.com/")
request_token, request_token_secret = oauth.get_request_token(params={"oauth_callback": "oob"})
authorize_url = oauth.get_authorize_url(request_token)
webbrowser.open(authorize_url)
verify = input('Enter code: ')
raw_access = oauth.get_raw_access_token(request_token,
request_token_secret,
params={"oauth_verifier": verify})
parsed_access_token = parse_utf8_qsl(raw_access.content)
access_token = (parsed_access_token['oauth_token'],
parsed_access_token['oauth_token_secret'])
start_time = time.time()
end_time = start_time + 3600
credentials['access_token'] = parsed_access_token['oauth_token']
credentials['access_token_secret'] = parsed_access_token['oauth_token_secret']
tokens = (credentials['access_token'], credentials['access_token_secret'])
s = oauth.get_session(tokens)
r = s.get('https://fantasysports.yahooapis.com/fantasy/v2/leagues;league_keys=nba.l.60379', params={'format': 'json'})
print(r.status_code)
r.json()
打印{u'错误':{u'说明':你'内部服务器错误',你' lang':你'的en-US'}}
答案 0 :(得分:1)