Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf977b6

Browse files
committed
Adding error handling if the service is unavailable
Example:except zencoder.ZencoderResponseError as e: print "Error: {1} ({0})".format(e.http_response.status, httplib.responses[e.http_response.status]) print e.content
1 parent013ee83 commitaf977b6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

‎zencoder/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
fromcoreimportZencoder
2+
fromcoreimportZencoderResponseError
23

‎zencoder/core.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
classZencoderError(Exception):
2626
pass
2727

28+
classZencoderResponseError(Exception):
29+
def__init__(self,http_response,content):
30+
self.http_response=http_response
31+
self.content=content
32+
2833
classHTTPBackend(object):
2934
"""
3035
Abstracts out an HTTP backend, but defaults to httplib2
@@ -117,10 +122,16 @@ def process(self, http_response, content):
117122
"""
118123
Returns HTTP backend agnostic Response data
119124
"""
120-
code=http_response.status
121-
body=self.decode(content)
122-
response=Response(code,body,content,http_response)
123-
returnresponse
125+
126+
try:
127+
code=http_response.status
128+
body=self.decode(content)
129+
response=Response(code,body,content,http_response)
130+
131+
returnresponse
132+
133+
exceptValueErrorase:
134+
raiseZencoderResponseError(http_response,content)
124135

125136
classZencoder(object):
126137
""" This is the entry point to the Zencoder API """

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp