@@ -118,7 +118,10 @@ def __init__(self, host, meta):
118
118
#Store version as triple and check dev flag
119
119
self .version = meta .get ("version" , None )
120
120
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." )
122
125
123
126
if len (self .version ) > 3 and self .version [3 ] == "Dev" :
124
127
self .is_dev = True
@@ -987,7 +990,7 @@ def upload(self, entity_type, entity_id, path, field_name=None,
987
990
params ["file" ] = open (path , "rb" )
988
991
989
992
# Create opener with extended form post support
990
- opener = urllib2 . build_opener (FormPostHandler )
993
+ opener = self . _build_opener (FormPostHandler )
991
994
992
995
# Perform the request
993
996
try :
@@ -1021,15 +1024,17 @@ def download_attachment(self, attachment_id):
1021
1024
1022
1025
:returns: binary data as a string
1023
1026
"""
1024
-
1027
+ # Cookie for auth
1025
1028
sid = self ._get_session_token ()
1026
1029
cj = cookielib .LWPCookieJar ()
1027
1030
c = cookielib .Cookie ('0' , '_session_id' , sid , None , False ,
1028
1031
self .config .server , False , False , "/" , True , False , None , True ,
1029
1032
None , None , {})
1030
1033
cj .set_cookie (c )
1031
1034
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
+
1033
1038
url = urlparse .urlunparse ((self .config .scheme , self .config .server ,
1034
1039
"/file_serve/attachment/%s" % urllib .quote (str (attachment_id )),
1035
1040
None , None , None ))
@@ -1101,6 +1106,22 @@ def _get_session_token(self):
1101
1106
self .config .session_token = session_token
1102
1107
return self .config .session_token
1103
1108
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
+
1104
1125
# Deprecated methods from old wrapper
1105
1126
def schema (self , entity_type ):
1106
1127
raise ShotgunError ("Deprecated: use schema_field_read('type':'%s') "
0 commit comments