Python 3: I have the issue : ValueError: not enough values to unpack (expected 2, got 0) in a really simple script:

Python 3: I have the issue : ValueError: not enough values to unpack (expected 2, got 0) in a really simple script:

我想用 pcloud 上传一个文件,这是我的代码:

import requests
url = 'https://api.pcloud.com/uploadfile'
path = 'C:\Users\MyName\Desktop\Folder\log.txt'
files = {open(path, 'rb')}
data = {'username': 'emailadress@gmail.com', 'password': 'mypassword'}
r = requests.post(url, files=files, data=data)
print(r.text())

我遇到了以下问题:

ValueError: not enough values to unpack (expected 2, got 0)

files 应该是字典,但你创建了 set() -(都使用 {} 创建实例)

 files = {'file': open(path, 'rb')}

顺便说一句: 你必须使用 r.text 而没有 ()

r.json()() 得到结果作为 Python 的字典。