我正在使用我在github中找到的代码,我不得不修改一些东西,它可以工作,但有时(即使在工作时)它会给出索引错误页面超出范围,然后停止工作。
文件"bot.py",第36行,模块中
imageSource = pageTablearrayNum
IndexError:列表索引超出范围
以下是我的代码
import time
import requests
import tweepy
import urllib
import os
import random
page = 1
url = 'https://danbooru.donmai.us/posts.json?tags=shimakaze_(kantai_collection) rating:s&limit=1000&page='
consumer_key = ''
consumer_secret = ''
access_key = ''
access_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
while True:
try:
random.seed()
jsURL = url + str(random.randint(1,1000))
response = requests.get(jsURL)
pageTable = response.json()
arrayNum = random.randint(0,5)
print arrayNum
imageSource = pageTable[arrayNum]["file_url"]
imageURL = imageSource
print imageURL
sourceURL = "http://danbooru.donmai.us/posts/" + str(pageTable[arrayNum]["id"])
print sourceURL
urllib.urlretrieve(imageURL, 'image.jpg')
.
tweetString = sourceURL + " "
api.update_with_media('image.jpg', status=tweetString)
os.remove('image.jpg')
post. Limited to 500 requests/hour.
time.sleep(600)
except tweepy.error.TweepError:
print "Image too large, finding a different image.."
arrayNum = random.randint(0,5)
代码行给出了错误,该代码生成了一个0-5的数字,并用作danbooru页面,所以我不知道为什么它会给出一个IndexError
https://stackoverflow.com/questions/52084719
复制相似问题