rkat
rkat

Reputation: 11

Trying to use Yahoo Fantasy Sports API with python but getting internal server error

I'm trying to learn how to use the YahooApi, but when getting the data from the website, it gives me an internal server error. I have tried every combination of league or leagues data or even general game data, but everything is giving me an internal server error. I have attached my code below and any help I could receive would be very helpful.

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()

And that prints {u'error': {u'description': u'Internal server error', u'lang': u'en-US'}}

Upvotes: 0

Views: 1412

Answers (1)

Victor Mora
Victor Mora

Reputation: 23

seems like this issues stems from Yahoo's side. One user reported trying OAuth2 authentication which seemed to work fine.

https://forums.yahoo.net/t5/Help-with-Fantasy-Baseball/Receiving-500-quot-Internal-Server-Error-quot-from-Yahoo-Fantasy/td-p/341427/page/4

Upvotes: 1

Related Questions