@@ -122,7 +122,10 @@ def __init__(self, host, meta):
122
122
#Store version as triple and check dev flag
123
123
self .version = meta .get ("version" , None )
124
124
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." )
126
129
127
130
if len (self .version ) > 3 and self .version [3 ] == "Dev" :
128
131
self .is_dev = True
@@ -991,7 +994,7 @@ def upload(self, entity_type, entity_id, path, field_name=None,
991
994
params ["file" ] = open (path , "rb" )
992
995
993
996
# Create opener with extended form post support
994
- opener = urllib2 . build_opener (FormPostHandler )
997
+ opener = self . _build_opener (FormPostHandler )
995
998
996
999
# Perform the request
997
1000
try :
@@ -1025,15 +1028,17 @@ def download_attachment(self, attachment_id):
1025
1028
1026
1029
:returns: binary data as a string
1027
1030
"""
1028
-
1031
+ # Cookie for auth
1029
1032
sid = self ._get_session_token ()
1030
1033
cj = cookielib .LWPCookieJar ()
1031
1034
c = cookielib .Cookie ('0' , '_session_id' , sid , None , False ,
1032
1035
self .config .server , False , False , "/" , True , False , None , True ,
1033
1036
None , None , {})
1034
1037
cj .set_cookie (c )
1035
1038
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
+
1037
1042
url = urlparse .urlunparse ((self .config .scheme , self .config .server ,
1038
1043
"/file_serve/attachment/%s" % urllib .quote (str (attachment_id )),
1039
1044
None , None , None ))
@@ -1104,6 +1109,22 @@ def _get_session_token(self):
1104
1109
self .config .session_token = session_token
1105
1110
return self .config .session_token
1106
1111
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
+
1107
1128
# Deprecated methods from old wrapper
1108
1129
def schema (self , entity_type ):
1109
1130
raise ShotgunError ("Deprecated: use schema_field_read('type':'%s') "
0 commit comments