mtbentley / duplicity_b2

A duplicity backend for BackBlaze's B2 file storage
MIT License
27 stars 7 forks source link

404 Error for filename with "+" #11

Open atYuguo opened 7 years ago

atYuguo commented 7 years ago

Duplicity version: 0.7.11

Upload CMD:

duplicity --encrypt-sign-key $KEYID $SOURCE par2+b2://$ACCOUNTID:$APPLICATIONKEY@$B2BUCKETNAME/$TARGET

usually get filename with "+" in it. Then try

duplicity list-current-files par2+b2://$ACCOUNTID:$APPLICATIONKEY@$B2BUCKETNAME/$TARGET

get error:

Attempt 1 failed. HTTPError: HTTP Error 404: Not Found

. It turns out that b2 enforce using "percent encoding":

When downloading a file by name, the file name must be URL-encoded before appending it to the download URL. And when using a query string instead of passing a JSON request, the parameters must all be URL-encoded.

The characters that do not need percent-encoding are a subset of the printable ASCII characters: upper-case letters, lower-case letters, digits, ".", "_", "-", "/", "~", "!", "$", "'", "(", ")", "*", ";", "=", ":", and "@". All other byte values in a UTF-8 must be replaced with "%" and the two-digit hex value of the byte.

This list of safe characters is safe in HTTP headers, in URL paths, and in URL query strings. Some characters, such as "&" are safe in some contexts and not others. For consistency, B2 requires %-encoding them all the time. You may %-encode all characters if you prefer, except that you may not encode "/" as "%2F" when used in a URL path.

The "+" character is a special case that is used to encode spaces. B2 will always encode a space as "+", and will accept either "+" or "%20". A plus sign must be percent-encoded as "%2B".

Fix:


95c95
<       url = self.download_url + \
---
>         url = self.download_url + \
97c97
<             urllib2.quote(remote_filename)
---
>             remote_filename

Thank you.