@@ -2702,14 +2702,16 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
2702
2702
if url is None :
2703
2703
return None
2704
2704
2705
- # We only need to set the auth cookie for downloads from Shotgun server
2705
+ cookie_handler = None
2706
2706
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 ()
2708
2709
2710
+ opener = self ._build_opener (cookie_handler )
2709
2711
try :
2710
2712
request = urllib .request .Request (url )
2711
2713
request .add_header ("user-agent" , "; " .join (self ._user_agents ))
2712
- req = urllib . request . urlopen (request )
2714
+ req = opener . open (request )
2713
2715
if file_path :
2714
2716
shutil .copyfileobj (req , fp )
2715
2717
else :
@@ -2750,21 +2752,21 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
2750
2752
else :
2751
2753
return attachment
2752
2754
2753
- def set_up_auth_cookie (self ):
2755
+ def get_auth_cookie_handler (self ):
2754
2756
"""
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.
2756
2759
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.
2759
2763
"""
2760
2764
sid = self .get_session_token ()
2761
2765
cj = http_cookiejar .LWPCookieJar ()
2762
2766
c = http_cookiejar .Cookie ("0" , "_session_id" , sid , None , False , self .config .server , False ,
2763
2767
False , "/" , True , False , None , True , None , None , {})
2764
2768
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 )
2768
2770
2769
2771
def get_attachment_download_url (self , attachment ):
2770
2772
"""
0 commit comments