无法通过商业帐户使用ImgurPython库

时间:2019-05-08 05:47:17

标签: imgur

我想上传一堆我在本地存储的图像,大约9000张左右。我写了一个Python脚本来遍历这些图像,并使用ImgurPython库将它们一张一张地上传。

由于我的应用程序仅供个人使用,因此我开始使用免费套餐非商业上传。但是,每个IP速率限制为50张图像。我的应用程序在抛出错误之前上传了50张图片。之后,我调查了商业选项并签署了商业计划,以便可以上传更多图像,然后再不受速率限制的影响。我使用的是相同的代码,除了我在mashape_key中添加以表示这是一个商业帐户之外。

但是,由于某种原因,每次我尝试上传图片时,相同的上传代码都会引发错误。

这是我的代码:

from imgurpython import ImgurClient
import json

client_id = 'censored'
client_secret = 'censored'
access_token = 'censored'
refresh_token = 'censored'
mashape_key = 'censored'

client = ImgurClient(client_id, client_secret, access_token, refresh_token, mashape_key)

# ....... this is where we load the data


# after loading the data, we now have a list called card_list
# this list contains images of trading cards
# we want to iterate through it and upload each image one-by-one
for card in card_list: 
    counter = counter + 1
    print(counter)
    if (counter > starting_point):
        name = card['name']
        image_path = 'images/' + name + '.jpg'
        print('Uploading ' + name + '...') 
        image = client.upload_from_path(image_path, anon=False)
        link = image['link']
        with open('image_links.tsv', "a+") as file:
            image_string = '<img src="' + link + '" class="center">'
            file.write(name + '\t' + image_string + '\n')

我想要的输出是一个.tsv文件(制表符分隔的值),其中包含图像的名称,后跟一个制表符,然后是用于在网页上显示该图像的html。

相反,图像变量是以下字典:

{'message':'Endpoint / 3 / upload不存在'}

库中的某些内部文件似乎无法将图像上传到正确的端点。

我该如何解决?

0 个答案:

没有答案