Skip to content

Commit 2fe3217

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1953924 + e7730ab commit 2fe3217

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
@@ -122,7 +122,10 @@ def __init__(self, host, meta):
122122
#Store version as triple and check dev flag
123123
self.version = meta.get("version", None)
124124
if not self.version:
125-
raise ShotgunError("Server version not specified")
125+
raise ShotgunError("The Shotgun Server didn't respond with a version number. "
126+
"This may be because you are running an older version of "
127+
"Shotgun against a more recent version of the Shotgun API. "
128+
"For more information, please contact the Shotgun Support.")
126129

127130
if len(self.version) > 3 and self.version[3] == "Dev":
128131
self.is_dev = True
@@ -991,7 +994,7 @@ def upload(self, entity_type, entity_id, path, field_name=None,
991994
params["file"] = open(path, "rb")
992995

993996
# Create opener with extended form post support
994-
opener = urllib2.build_opener(FormPostHandler)
997+
opener = self._build_opener(FormPostHandler)
995998

996999
# Perform the request
9971000
try:
@@ -1025,15 +1028,17 @@ def download_attachment(self, attachment_id):
10251028
10261029
:returns: binary data as a string
10271030
"""
1028-
1031+
# Cookie for auth
10291032
sid = self._get_session_token()
10301033
cj = cookielib.LWPCookieJar()
10311034
c = cookielib.Cookie('0', '_session_id', sid, None, False,
10321035
self.config.server, False, False, "/", True, False, None, True,
10331036
None, None, {})
10341037
cj.set_cookie(c)
10351038
cookie_handler = urllib2.HTTPCookieProcessor(cj)
1036-
urllib2.install_opener(urllib2.build_opener(cookie_handler))
1039+
opener = self._build_opener(cookie_handler)
1040+
urllib2.install_opener(opener)
1041+
10371042
url = urlparse.urlunparse((self.config.scheme, self.config.server,
10381043
"/file_serve/attachment/%s" % urllib.quote(str(attachment_id)),
10391044
None, None, None))
@@ -1104,6 +1109,22 @@ def _get_session_token(self):
11041109
self.config.session_token = session_token
11051110
return self.config.session_token
11061111

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

0 commit comments

Comments
 (0)