Py学习  »  Python

python Pastebin API的问题:错误的API请求

haytham • 3 年前 • 1551 次点击  

你看,我一直在看pastebin api,我试图用python发出post请求,结果是当开发密钥api正确时,我收到错误错误的api请求,无效的api_dev_key。我甚至还创建了另一个帐户来测试这个错误是否是共享的,而且是共享的。

我看到有人有一个类似的错误,我通过将http更改为https来解决它,我尝试了它,但仍然不起作用,下面是代码:

import requests

dev_key = "--The Dev Key"
url = "https://pastebin.com/api/api_post.php"

def PostPastebinAPI(args):
    Lista_Errores = [
        "Bad API request, invalid api_option",
        "Bad API request, invalid api_dev_key",
        "Bad API request, maximum number of 25 unlisted pastes for your free account",
        "Bad API request, maximum number of 10 private pastes for your free account",
        "Bad API request, api_paste_code was empty",
        "Bad API request, maximum paste file size exceeded",
        "Bad API request, invalid api_paste_expire_date",
        "Bad API request, invalid api_paste_private",
        "Bad API request, invalid api_paste_format",
        "Bad API request, invalid api_user_key",
        "Bad API request, invalid or expired api_user_key",
        "Bad API request, you can't add paste to folder as guest"
    ]
    response = requests.post(url, args)
    
    for error in Lista_Errores:
        if response.text == error:
            return "Error en PastebinAPIPost: \n" "{}".format(error)
    
    return response.text
    
Post = PostPastebinAPI({
    "dev_key_api": "2gpdDFVdUNeze0fSnB6b9-FZJ8g2tlYV",
    "api_option": "paste",
    "api_paste_code": "Test"
})
print(Post)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133496
文章 [ 1 ]  |  最新文章 3 年前
Joran Beasley
Reply   •   1 楼
Joran Beasley    3 年前

尝试将其更改为api_dev_key?

Post = PostPastebinAPI({
    "api_dev_key": "<YOUR API KEY HERE>",
    "api_option": "paste",
    "api_paste_code": "Test"
})