Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SickRage
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
SickRage
Commits
9a269cfa
Commit
9a269cfa
authored
Jul 4, 2015
by
Dustyn Gibson
Browse files
Options
Downloads
Plain Diff
Merge branch 'trakt-exception' into develop
parents
096c6752
4311ff46
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/trakt/trakt.py
+28
-28
28 additions, 28 deletions
lib/trakt/trakt.py
with
28 additions
and
28 deletions
lib/trakt/trakt.py
+
28
−
28
View file @
9a269cfa
from
lib
import
requests
import
requests
import
certifi
import
json
import
sickbeard
import
time
...
...
@@ -8,7 +9,8 @@ from exceptions import traktException, traktAuthException, traktServerBusy
class
TraktAPI
():
def
__init__
(
self
,
disable_ssl_verify
=
False
,
timeout
=
30
):
self
.
verify
=
not
disable_ssl_verify
self
.
session
=
requests
.
Session
()
self
.
verify
=
certifi
.
where
()
if
not
disable_ssl_verify
else
False
self
.
timeout
=
timeout
if
timeout
else
None
self
.
auth_url
=
sickbeard
.
TRAKT_OAUTH_URL
self
.
api_url
=
sickbeard
.
TRAKT_API_URL
...
...
@@ -65,9 +67,7 @@ class TraktAPI():
def
traktRequest
(
self
,
path
,
data
=
None
,
headers
=
None
,
url
=
None
,
method
=
'
GET
'
,
count
=
0
):
if
None
==
url
:
url
=
self
.
api_url
+
path
else
:
url
=
url
+
path
url
=
self
.
api_url
count
=
count
+
1
...
...
@@ -76,12 +76,12 @@ class TraktAPI():
if
None
==
sickbeard
.
TRAKT_ACCESS_TOKEN
:
logger
.
log
(
u
'
You must get a Trakt TOKEN. Check your Trakt settings
'
,
logger
.
WARNING
)
r
aise
traktAuthException
(
e
)
r
eturn
{}
headers
[
'
Authorization
'
]
=
'
Bearer
'
+
sickbeard
.
TRAKT_ACCESS_TOKEN
try
:
resp
=
requests
.
request
(
method
,
url
,
headers
=
headers
,
timeout
=
self
.
timeout
,
resp
=
self
.
session
.
request
(
method
,
url
+
path
,
headers
=
headers
,
timeout
=
self
.
timeout
,
data
=
json
.
dumps
(
data
)
if
data
else
[],
verify
=
self
.
verify
)
# check for http errors and raise if any are present
...
...
@@ -98,16 +98,16 @@ class TraktAPI():
elif
code
==
502
:
# Retry the request, cloudflare had a proxying issue
logger
.
log
(
u
'
Retrying trakt api request: %s
'
%
path
,
logger
.
WARNING
)
return
self
.
traktRequest
(
path
,
data
,
headers
,
method
)
return
self
.
traktRequest
(
path
,
data
,
headers
,
url
,
method
)
elif
code
==
401
:
logger
.
log
(
u
'
Unauthorized. Please check your Trakt settings
'
,
logger
.
WARNING
)
if
self
.
traktToken
(
refresh
=
True
,
count
=
count
):
return
self
.
traktRequest
(
path
,
data
,
url
,
method
)
return
self
.
traktRequest
(
path
,
data
,
headers
,
url
,
method
)
raise
traktAuthException
(
e
)
elif
code
in
(
500
,
501
,
503
,
504
,
520
,
521
,
522
):
#http://docs.trakt.apiary.io/#introduction/status-codes
logger
.
log
(
u
'
Trakt may have some issues and it
\'
s unavailable. Try again later please
'
,
logger
.
WARNING
)
r
aise
traktServerBusy
(
e
)
r
eturn
{}
else
:
raise
traktException
(
e
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment