Skip to content

Commit 30f0a58

Browse files
committed
Merge remote-tracking branch 'upstream/master' into relative_import_test
2 parents a7d430b + e7730ab commit 30f0a58

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

shotgun_api3/shotgun.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def __init__(self, host, meta):
118118
#Store version as triple and check dev flag
119119
self.version = meta.get("version", None)
120120
if not self.version:
121-
raise ShotgunError("Server version not specified")
121+
raise ShotgunError("The Shotgun Server didn't respond with a version number. "
122+
"This may be because you are running an older version of "
123+
"Shotgun against a more recent version of the Shotgun API. "
124+
"For more information, please contact the Shotgun Support.")
122125

123126
if len(self.version) > 3 and self.version[3] == "Dev":
124127
self.is_dev = True
@@ -987,7 +990,7 @@ def upload(self, entity_type, entity_id, path, field_name=None,
987990
params["file"] = open(path, "rb")
988991

989992
# Create opener with extended form post support
990-
opener = urllib2.build_opener(FormPostHandler)
993+
opener = self._build_opener(FormPostHandler)
991994

992995
# Perform the request
993996
try:
@@ -1021,15 +1024,17 @@ def download_attachment(self, attachment_id):
10211024
10221025
:returns: binary data as a string
10231026
"""
1024-
1027+
# Cookie for auth
10251028
sid = self._get_session_token()
10261029
cj = cookielib.LWPCookieJar()
10271030
c = cookielib.Cookie('0', '_session_id', sid, None, False,
10281031
self.config.server, False, False, "/", True, False, None, True,
10291032
None, None, {})
10301033
cj.set_cookie(c)
10311034
cookie_handler = urllib2.HTTPCookieProcessor(cj)
1032-
urllib2.install_opener(urllib2.build_opener(cookie_handler))
1035+
opener = self._build_opener(cookie_handler)
1036+
urllib2.install_opener(opener)
1037+
10331038
url = urlparse.urlunparse((self.config.scheme, self.config.server,
10341039
"/file_serve/attachment/%s" % urllib.quote(str(attachment_id)),
10351040
None, None, None))
@@ -1101,6 +1106,22 @@ def _get_session_token(self):
11011106
self.config.session_token = session_token
11021107
return self.config.session_token
11031108

1109+
def _build_opener(self, handler):
1110+
"""Build urllib2 opener with appropriate proxy handler."""
1111+
if self.config.proxy_server:
1112+
# handle proxy auth
1113+
if self.config.proxy_user and self.config.proxy_pass:
1114+
auth_string = "%s:%s@" % (self.config.proxy_user, self.config.proxy_pass)
1115+
else:
1116+
auth_string = ""
1117+
proxy_addr = "http://%s%s:%d" % (auth_string, self.config.proxy_server, self.config.proxy_port)
1118+
proxy_support = urllib2.ProxyHandler({self.config.scheme : proxy_addr})
1119+
1120+
opener = urllib2.build_opener(proxy_support, handler)
1121+
else:
1122+
opener = urllib2.build_opener(handler)
1123+
return opener
1124+
11041125
# Deprecated methods from old wrapper
11051126
def schema(self, entity_type):
11061127
raise ShotgunError("Deprecated: use schema_field_read('type':'%s') "

0 commit comments

Comments
 (0)