简体   繁体   English

TypeError:String Indices必须是整数; Python 2.7.8

[英]TypeError: String Indices must be integers; Python 2.7.8

Recently I downloaded and attempted to use an open source device which has had it's support shut down for quite some time. 最近我下载并试图使用一个开源设备,它已经支持关闭了很长一段时间。 When I attempt to run the program I get the error "TypeError: String Indices must be integers". 当我尝试运行程序时,我收到错误“TypeError:String Indices必须是整数”。 Ive had a look around for a solution but as python is not something Im accustomed to, I think the solutions are going over my head, or do not suit my issue. 我曾经四处寻找解决方案,但由于python不是我习以为常的东西,我认为解决方案已经超出我的想象,或者不适合我的问题。

The Full Error Code: 完整错误代码:

File "e621dl.py, line 93, in <module>
   Current_page, defailt.MAX_RESULTS>
File "..\e621_api.py" line 30, in get_posts uploads.append(UPLOAD(post['file_url], post['md5], post['file_ext']))
TypeError: string indices must be integers.

Firstly I apologise for my incompitance if this is a really really easy fix, and secondly, Here is the code; 首先,如果这是一个非常简单的解决方案,我为我的不成功道歉,其次,这是代码;

#!/usr/bin/env python

from json import loads
from support import SpoofOpen
from collections import namedtuple
import logging

UPLOAD = namedtuple('Upload', 'url md5 ext')
SPOOF = SpoofOpen()

LIST_BASE = 'https://e621.net/post/index.json?'
TAGS = 'tags='
DATE = ' date:>'
PAGE = '&page='
MAX = '&limit='

def get_posts(search_term, uploaded_after, page_num, max_results):
    request = LIST_BASE + \
        TAGS + search_term + \
        DATE + str(uploaded_after) + \
        PAGE + str(page_num) + \
        MAX + str(max_results)

    log = logging.getLogger('e621_api')
    log.debug('search url = ' + request)
    results = loads(SPOOF.open(request).read().decode())

    uploads = []
    for post in results:
        uploads.append(UPLOAD(post['file_url'], post['md5'], post['file_ext']))
    return uploads

def download(url, filename):
    with open(filename, 'wb') as dest:
        source = SPOOF.open(url)
        dest.write(source.read())

For those of you using this particular tool, I ran into this error when specifying more than 6 tags at a time per line. 对于那些使用此特定工具的人,我在每行指定一次超过6个标记时遇到此错误。 Reducing the number of tags per line/search in the tags.txt file to 6 tags resolved this error for me. 将tags.txt文件中每行/搜索的标签数量减少到6个标签为我解决了这个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM