““缩进中的制表符和空格的使用不一致”

时间:2018-07-17 04:48:12

标签: python

我已经下载了该文件,无法运行它。它一直显示此错误: enter image description here

我尝试取消制表并再次制表,将制表符长度分别设置为4和8,但没有任何变化:(请帮助

from fbchat import Client, log
from getpass import getpass
from datetime import datetime
import sys, os, urllib, time, socket, shutil, requests
from glob import glob
from zipfile import ZipFile

socket.setdefaulttimeout(60)
reload(sys)
sys.setdefaultencoding("utf-8")

ending = '</div></div>'

username = str(raw_input("Username: "))
password = getpass()

client = Client(username, password)

zipping = str(raw_input("Want to save your data as a .Zip file y/n?: "))

uid = client.uid
USER = client.fetchUserInfo(client.uid)[client.uid]
self = USER.name

ID = []
NAME = []

docs = ['docx', 'doc', 'pdf', 'pptx', 'txt', 'xlsx']
media = ['mp3', 'mp4', 'aac', 'webm', 'avi', '3gp']
gen = ['jpg', 'png']

def download_file(add, name):
    request = requests.get(add, timeout=60, stream=True)
    #Open the output file and make sure we write in binary mode
    flag = 0
    with open(name, 'wb') as fh:
        # Walk through the request response in chunks of 1024 * 1024 bytes, so 1MiB
        for chunk in request.iter_content(1024 * 1024):
            # Write the chunk to the file
        flag += 1
        if flag > 10:
            Log_file.write("This file is bigger than 10MB so download it if you want-- " + add + '\n\n')
            break
        fh.write(chunk)

2 个答案:

答案 0 :(得分:0)

就像错误消息所暗示的那样,请勿混合使用空格和制表符。使用您的编辑器将所有选项卡(在正则表达式模式下搜索\t)替换为4个空格,代码应该可以正常工作。

答案 1 :(得分:-1)

您应该在for循环下编写代码“将块写入文件”。请把它放在for循环中:

for chunk in request.iter_content(1024 * 1024):