uberfastman / yfpy

Python API wrapper for the Yahoo Fantasy Sports public API (supports NFL, NHL, MLB, and NBA).
https://pypi.org/project/yfpy/
GNU General Public License v3.0
189 stars 49 forks source link

Trouble Running test.py #7

Closed adoreste319 closed 4 years ago

adoreste319 commented 4 years ago

Hello, I have successfully created an app with a subsequent client id/secret. As well, in test.py I have changed the auth_dir variable to the private.json file path; however, after running test.py I get the following behavior:

test_get_all_yahoo_fantasy_game_keys (main.QueryTestCase) Retrieve all Yahoo fantasy football game keys. ... Enter verifier : hrurpuf ERROR

It happens to every unit test and it also opens a webpage with a new verifier every time a unit test case is ran. In the readme you state the following "The path to this file will be needed to point YFPY to your credentials." Where exactly do I have to specify the private.json file path? Or could something else be wrong?

uberfastman commented 4 years ago

Hi @adoreste319, my apologies for the delayed response. Anyway, could post your full error stack trace so I can see what exactly the tests are complaining about?

Just to double check I tried running all the test cases with new credentials, moved private.json around, tried again, etc. and all seemed to work as expected, but of course that is only on my machine so we'll have to figure out what's happening for you.

The app should generate at token.json file after you've entered the verifier code and it's authenticated, which will then prevent it from asking for a verifier every time, so obviously something is a little off. But I'm sure we can get it sorted!

In response to your question, you can either just place private.json with your Yahoo app credentials in the test/ directory, OR you can modify the auth_dir path to the private.json file in test.py as it sounds like you did. Both should work. What operating system are you using? YFPY should be OS-agnostic, but maybe if you input a path into test.py with slashes going the wrong direction for your OS it could cause an issue...? But if you're getting to the verifier stage then I don't think that's a likely culprit.

Anyway, if you could please share more context (the full error message), I will do my best to get you up and running!

jfacowns commented 4 years ago

This exact same issue is happening to me as well, repeated verification requests without any of them being accepted.

uberfastman commented 4 years ago

Hi @jfacowns, could you share your error stacktrace? What OS are you on?

I’ve been unable to replicate the issue, so I need more information about what’s happening to try and recreate the error or diagnose what’s causing it.

Yahoo has a nasty habit of randomly changing things about their API so I want to make sure it’s not some backend change that I’ll have to make changes to support.

jfacowns commented 4 years ago

I'm not great with Python and I'm also pretty new to Github. I'm not aware of how to do a stack trace in Python.

I'm running win 10 and using chrome as my default browser. What's kind of strange about this is that I have 2FA enabled on my yahoo account and each time i input the code that that gets generated when the yahoo site pops up, i actually get an email from yahoo saying my sign in was successful.

Your Yahoo account "" was just used to sign in on "" . If you did this, you’re all set.

If not, please use this link to stop sharing, and create a new password.

So it kind of appears to work, but the test.py script repeatedly tells me I code wrong.

adoreste319 commented 4 years ago

Hi @uberfastman, here's the error stackframe when any unit test tries to run and after I input the secret login code provided to me by the Yahoo authentication procedure:

====================================================================== ERROR: test_get_all_yahoo_fantasy_game_keys (main.QueryTestCase) Retrieve all Yahoo fantasy football game keys.

Traceback (most recent call last): File "C:\Users\Alexis\Downloads\winter2020\eecs497\test.py", line 64, in setUp self.yahoo_query = YahooFantasySportsQuery(auth_dir, self.league_id, game_id=self.game_id, File "C:\Program Files\Python38\Lib\site-packages\yfpy\query.py", line 85, in init self.oauth = OAuth2(None, None, from_file=token_file_path) File "C:\Program Files\Python38\Lib\site-packages\yahoo_oauth\yahoo_oauth.py", line 229, in init super(OAuth2, self).init('oauth2', consumer_key, consumer_secret, **kwargs) File "C:\Program Files\Python38\Lib\site-packages\yahoo_oauth\yahoo_oauth.py", line 89, in init data.update(self.handler()) File "C:\Program Files\Python38\Lib\site-packages\yahoo_oauth\yahoo_oauth.py", line 143, in handler credentials.update(self.oauth2_access_parser(raw_access)) File "C:\Program Files\Python38\Lib\site-packages\yahoo_oauth\yahoo_oauth.py", line 165, in oauth2_access_parser self.guid = parsed_access['xoauth_yahoo_guid'] KeyError: 'xoauth_yahoo_guid'

It happens with every unit test and the authorization process repeats per every function unit test. I am running this on the python 3.8.1 shell on a win10 64-bit machine. Let me know what you think could be wrong, or if it is something wrong on my end either locally or on my Yahoo account.

edvard-munch commented 4 years ago

I've ran into the same problem. Getting the same error message. But I'm not running your tests.py file. I'm using a function from your library to get YahooFantasySportsQuery object.

My code:

import yfpy

TOKEN_PATH = '/home/arkadiy-dev/programming/py/yahoo_fantasy_nhl'

print(yfpy.query.YahooFantasySportsQuery(TOKEN_PATH, 5824, game_code='nhl'))

Traceback:

Traceback (most recent call last): File "test_new.py", line 5, in print(yfpy.query.YahooFantasySportsQuery(TOKEN_PATH, 5824, game_code='nhl')) File "/home/arkadiy-dev/programming/py/yahoo_fantasy_nhl/venv/lib/python3.7/site-packages/yfpy/query.py", line 86, in init self.oauth = OAuth2(None, None, from_file=token_file_path) File "/home/arkadiy-dev/programming/py/yahoo_fantasy_nhl/venv/lib/python3.7/site-packages/yahoo_oauth/yahoo_oauth.py", line 239, in init super(OAuth2, self).init('oauth2', consumer_key, consumer_secret, **kwargs) File "/home/arkadiy-dev/programming/py/yahoo_fantasy_nhl/venv/lib/python3.7/site-packages/yahoo_oauth/yahoo_oauth.py", line 89, in init data.update(self.handler()) File "/home/arkadiy-dev/programming/py/yahoo_fantasy_nhl/venv/lib/python3.7/site-packages/yahoo_oauth/yahoo_oauth.py", line 147, in handler credentials.update(self.oauth2_access_parser(raw_access)) File "/home/arkadiy-dev/programming/py/yahoo_fantasy_nhl/venv/lib/python3.7/site-packages/yahoo_oauth/yahoo_oauth.py", line 171, in oauth2_access_parser self.guid = parsed_access['xoauth_yahoo_guid'] KeyError: 'xoauth_yahoo_guid'

I've tried to get to the bottom of the problem. And gone down from your query.py file to the sessions .py from requests library. And it looks like we are just not getting this xoauth_yahoo_guid parameter in response body. Despite that we are sending all of the needed parameters in request body.

Then I started researching again. Found some related SO questions. And it turned out that Yahoo OAuth 2 login flow is down at the moment. So it shouldn't work for everybody. @uberfastman , but you said it works for you? Not sure how this is possible.

SO questions I'm talking about: https://stackoverflow.com/questions/51940949/yahoo-oauth-and-oauth2-0-login-malfunction https://stackoverflow.com/questions/51836627/yahoo-oauth-2-0-login-malfunction/52111529#52111529

ChadShoeby commented 4 years ago

Writing because I'm getting a similar issue. If Yahoo is down, I'm hoping to save others a lot of googling and headache.

I'm getting this error "EOF when reading a line" on site-packages/yahoo_oauth/yahoo_oauth.py in handler, line 116 : self.verifier = input("Enter verifier : ")

Line 115 is webbrowser.open(authorize_url)

No window opens for me. I can see a token.json file in the same dir as the private.json, which from the docs seems expected. This would be consistent with yahoo oauth being down. I never see a confirm window and I never get a verification code.

I'm on Mac OS and using Docker python django. I'm using a self signed cert to serve the https endpoint, so my next step will be to try and use a registered cert.

ChadShoeby commented 4 years ago

@edvard-munch @uberfastman Okay so Yahoo isn't down. This issue looks like this recently closed issue in the yahoo-oauth dependency. https://github.com/josuebrunel/yahoo-oauth/issues/54#issuecomment-609518226

Long story short, for some reason the "xoauth_yahoo_guid" is not being returned in response from Yahoo. This might be temporary. I applied the fix directly and it all mostly works now. JosueBrunel applied a fix a few days ago to the dependency.

If you don't want to update to that version, in this file site-packages/yahoo_oauth/yahoo_oauth.py at about line 166 change: self.guid = parsed_access.get('xoauth_yahoo_guid') to: self.guid = parsed_access.get('xoauth_yahoo_guid', None)

uberfastman commented 4 years ago

So I want to give a big shoutout to @ChadShoeby for figuring out this issue, and to @kraft87 for making a PR (ages ago) to fix it, which I've finally incorporated. I've since updated yfpy on PyPi to v3.1.2, which includes those fixes, and the tests all seem to be working again, at least for now.

Also thanks to the other posters on this issue thread for your input and assistance!