Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for API V2 #60

Merged
merged 1 commit into from
Sep 16, 2017
Merged

Fixes for API V2 #60

merged 1 commit into from
Sep 16, 2017

Conversation

mspieth
Copy link
Contributor

@mspieth mspieth commented Aug 12, 2017

  • More Logging
  • parameter keys assigned correctly
  • Cache uses Accept-Language as part of the key but nothing else from
    the headers
  • Cache is pruned at start
  • Additional exceptions for new errors
  • Check cache before authorization so there is no network traffic
    if not required
  • Add langauge key for v1 compatability
  • Add extra banners keys
  • Add raw banners for easier filtering

@mspieth
Copy link
Contributor Author

mspieth commented Aug 12, 2017

Note there is a pull request MythTV/mythtv#141 for mythtv which has all these changes + doctests in ttvdb.py which run and generate the same output on both python 2.7.13 and 3.5.4.
Cache works well for this script.

@dbr
Copy link
Owner

dbr commented Aug 12, 2017

I don't understand the cache_key stuff, at least based of the comments in the code - can you explain why it is necessary?

Also all the tests are failing on Travis (ignore Appveyor as I have set it up incorrectly)

@mspieth
Copy link
Contributor Author

mspieth commented Aug 12, 2017

A new cache_key algo is required as the authentication token changes with each run. Also there are other header params which also change with each request (e.g. timestamp). Excluding all headers means that Accept-Language is excluded which means different language requests will return the cached response from the wrong language.
The _loadurl part checks the cache before a get is performed so that an auth token can be obtained. If the response is already in the cache, the auth token is not required. This prevents the need to do a get which may access the host and fail because the session is not yet not authorized. It is not necessary to authorize if the cache is to be used thus saving host and network traffic.

@mspieth
Copy link
Contributor Author

mspieth commented Aug 12, 2017

I'm not sure why the tests are failing, Im assuming it has to do with auth and I also don't understand how key without username and userkey can succeed unless it is a special. It will probably means that auth will fail as it will attempt to do it with a blank username/userkey. I will investigate further and try to understand the unit tests. The ttvdb doctests are quite extensive but use the mythtv account for auth which is a proper account on thetvdb.com. This could be the difference. These commits are a backport/merge from the mythtv commits.

* More Logging
* parameter keys assigned correctly
* Cache uses Accept-Language as part of the key but nothing else from
  the headers
* Cache is pruned at start
* Additional exceptions for new errors
* Check cache before authorization so there is no network traffic
  if not required
* Add langauge key for v1 compatability
* Add extra banners keys
* Add raw banners for easier filtering
@mspieth
Copy link
Contributor Author

mspieth commented Aug 13, 2017

I had not considered a non standard cache or no cache.
That has been fixed.
pytest works under python 3 for me too. python2 I got a SSLError unprintable exceptions, not sure why but didn't chase it.
Note that the cache formats are incompatible between py2 and 3 due to pickling format and I could not resolve that.
The 2 "ResourceNotFound" and "InvalidLanguage" errors no longer raise exceptions (for now).
InvalidLanguage means there could be data just not as much.
ResourceNotFound means no data was found for the query.
banner test was changed to exclude raw which is a list not a dict so no item() method.
doctest will fail under py3 as the list repr outputs have unicode string prefixes and will not match even thought he body of the strings is the same.
commit was amended to suit.

@dbr dbr merged commit dd6ce4b into dbr:master Sep 16, 2017
@dbr
Copy link
Owner

dbr commented Sep 16, 2017

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants