@@ -2702,14 +2702,16 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
27022702 if url is None :
27032703 return None
27042704
2705- # We only need to set the auth cookie for downloads from Shotgun server
2705+ cookie_handler = None
27062706 if self .config .server in url :
2707- self .set_up_auth_cookie ()
2707+ # We only need to set the auth cookie for downloads from Shotgun server
2708+ cookie_handler = self .get_auth_cookie_handler ()
27082709
2710+ opener = self ._build_opener (cookie_handler )
27092711 try :
27102712 request = urllib .request .Request (url )
27112713 request .add_header ("user-agent" , "; " .join (self ._user_agents ))
2712- req = urllib . request . urlopen (request )
2714+ req = opener . open (request )
27132715 if file_path :
27142716 shutil .copyfileobj (req , fp )
27152717 else :
@@ -2750,21 +2752,21 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
27502752 else :
27512753 return attachment
27522754
2753- def set_up_auth_cookie (self ):
2755+ def get_auth_cookie_handler (self ):
27542756 """
2755- Set up urllib2 with a cookie for authentication on the Shotgun instance.
2757+ Return an urllib cookie handler containing a cookie for FPTR
2758+ authentication.
27562759
2757- Looks up session token and sets that in a cookie in the :mod:`urllib2` handler. This is
2758- used internally for downloading attachments from the Shotgun server.
2760+ Looks up session token and sets that in a cookie in the :mod:`urllib2`
2761+ handler.
2762+ This is used internally for downloading attachments from FPTR.
27592763 """
27602764 sid = self .get_session_token ()
27612765 cj = http_cookiejar .LWPCookieJar ()
27622766 c = http_cookiejar .Cookie ("0" , "_session_id" , sid , None , False , self .config .server , False ,
27632767 False , "/" , True , False , None , True , None , None , {})
27642768 cj .set_cookie (c )
2765- cookie_handler = urllib .request .HTTPCookieProcessor (cj )
2766- opener = self ._build_opener (cookie_handler )
2767- urllib .request .install_opener (opener )
2769+ return urllib .request .HTTPCookieProcessor (cj )
27682770
27692771 def get_attachment_download_url (self , attachment ):
27702772 """
0 commit comments