'Unsupported operand' when giving modes in 'put()' #871

bitprophet opened this Issue Mar 21, 2013 · 1 comment


None yet

2 participants


E.g.: in a call like put(StringIO(xxx), yyy, mode="0755") (emphasis is on mode string, not the StringIO, which is incidental):

Fatal error: put() encountered an exception while uploading '<StringIO.StringIO instance at 0x9ddfa8>'

Underlying exception:                                                                                 
    unsupported operand type(s) for &: 'str' and 'int'                                                


Problem is that whoever added the mode stuff is blindly doing lmode & 07777 which dies whenever lmode is a string. Casting to an int appears to work fine for me in the shell, regardless if one gives e.g. "755", "0755", "00755" etc.

@bitprophet bitprophet added a commit that referenced this issue Mar 22, 2013
@bitprophet bitprophet Changelogs re #870, #871 4101c22
@bitprophet bitprophet closed this Mar 22, 2013

Many thanks for the fix but I think it needs to be extended to handle the case when mode is passed in as an int or a string. Sorry for posting a diff, I know bad form.

         # Handle modes if necessary
         if (local_is_path and mirror_local_mode) or (mode is not None):
             lmode = os.stat(local_path).st_mode if mirror_local_mode else mode
-            lmode = lmode & 07777
+            if type(lmode) is str:
+                lmode = int(lmode, 8) & 07777
+            else:
+                lmode = lmode & 07777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment