【问题标题】:Uploading to anonfiles API with curl in python在 python 中使用 curl 上传到 anonfiles API
【发布时间】:2022-11-09 03:19:02
【问题描述】:

我想使用请求模块上传到anonfiles。代码运行,但文件未出现在网站上。到目前为止,这是我的代码:

import requests

files = {
    'file': ('file.txt', open('file.txt', 'rb')),
}
requests = requests.post('https://api.anonfiles.com/upload/?token=mytoken', files=files)

关于可能是什么问题的任何想法?提前致谢!

【问题讨论】:

  • 你在response 中得到了什么?也许有解释问题的消息。也许您使用了错误的参数或错误的令牌。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如它目前所写的那样,很难准确地说出你在问什么。

标签: python curl post python-requests


【解决方案1】:

您使用了错误的 URL - 最后必须没有 /

https://api.anonfiles.com/upload

而且似乎没有token也可以工作

import requests

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

url = 'https://api.anonfiles.com/upload'
response = requests.post(url, files=files)

data = response.json()

print(data['data']['file']['url']['short'])

文档:API

【讨论】:

  • 删除 / 使其工作。感谢您的建议。
  • @0xStefanos 您可以将我的答案标记为已接受,几分钟后您可以投票(但为此您可能需要更大的reputation score
【解决方案2】:

您可以随时尝试anonfile。这是一个 PyPI 库,已经包装了 anonfiles.com 的 api。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-21
    • 2016-05-31
    • 1970-01-01
    • 2012-10-27
    • 2020-02-29
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多