Search code examples
pythonhttpspcloud

PCloud Api Uploadfile with python


I have tried to upload a file with pcloud (https://api.pcloud.com/uploadfile?) using this URL:

https://api.pcloud.com/uploadfile?username=myemail&password=mypassword&path=/&filename=myfile

But I get the following error:

{
  "result": 0,
  "metadata": [

  ],
  "checksums": [

  ],
  "fileids": [

 ]
}

this is my example code on my windows:

import requests
import json

username = '[email protected]'
password = 'mypassword'
myfile   = r'd:\MUSIC\Get Lucky\01 - Border Reiver.mp3'
url      = "https://api.pcloud.com/uploadfile?username=%s&password=%s&path=/&filename=%s" % (username, password, myfile)
get = requests.get(url)

print json.loads(get.text)

Solution

  • Your code would need a POST with a Keep-Alive header.

    import requests
    session = requests.Session()
    files = {'01 - Border Reiver.mp3': open('d:\MUSIC\Get Lucky\01 - Border Reiver.mp3', 'rb')}
    data = {'username': '[email protected]', 'password': 'mypassword'}
    post = session.post('https://api.pcloud.com/uploadfile', files=files, data=data)
    print(post.json())
    

    For a more detailed example you might checkout out the Python wrapper for the pcloud API. It is available on PyPi and github. https://pypi.python.org/pypi/pcloud