Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use folderid with uploadfile method #63

Closed
ikwyl6 opened this issue Oct 16, 2022 · 1 comment
Closed

cannot use folderid with uploadfile method #63

ikwyl6 opened this issue Oct 16, 2022 · 1 comment

Comments

@ikwyl6
Copy link

ikwyl6 commented Oct 16, 2022

In my script that uses pycloud I cannot use folderid=folderid, where folderid is an integer, with the uploadfile method. It causes some exceptions and doesn't upload the file.

My script has fileinfo = pc.uploadfile(files=[upload_file], folderid=folderid) and is causes exceptions (see below). I have to change the folderid=folderid to path='/' like below:

fileinfo = pc.uploadfile(files=[upload_file], path='/')

The pcloud api says that path is discouraged but still accepted. In lieu of path it provides a folderid parameter: https://docs.pcloud.com/methods/file/uploadfile.html

Exceptions when folderid is used with pycloud.uploadfile:

  File "/pcloud-upload/./pcloud-upload.py", line 215, in <module>
    fileinfo = pc.uploadfile(files=[upload_file], folderid=folderid)
  File "/home/alarm/.local/lib/python3.10/site-packages/pcloud/validate.py", line 19, in wrapper
    return func(*args, **kwargs)
  File "/home/alarm/.local/lib/python3.10/site-packages/pcloud/api.py", line 274, in uploadfile
    return self._upload("uploadfile", files, **kwargs)
  File "/home/alarm/.local/lib/python3.10/site-packages/pcloud/api.py", line 242, in _upload
    m = MultipartEncoder(fields=fields)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 125, in __init__
    self._prepare_parts()
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in _prepare_parts
    self.parts = [Part.from_field(f, enc) for f in self._iter_fields()]
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in <listcomp>
    self.parts = [Part.from_field(f, enc) for f in self._iter_fields()]
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 494, in from_field
    body = coerce_data(field.data, encoding)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 472, in coerce_data
    return CustomBytesIO(data, encoding)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 535, in __init__
    buffer = encode_with(buffer, encoding)
  File "/usr/lib/python3.10/site-packages/requests_toolbelt/multipart/encoder.py", line 416, in encode_with
    return string.encode(encoding)
AttributeError: 'int' object has no attribute 'encode'

When I change folderid to using path then I get expected result, the file is uploaded.

tomgross added a commit that referenced this issue Oct 23, 2022
@tomgross
Copy link
Owner

Good catch @ikwyl6! Thanks.
The API call works, if you use folderid as string. But since the API documents it as int I added a fix here: 110c114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants