0

I have downloaded this file and can't run it. It keeps showing this error: enter image description here

I tried untab and tab it again, put the tab length to 4 and 8 but nothing changes :( Please help

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)
Trung Hà
  • 17
  • 1
  • 6

2 Answers2

0

Like the error message suggests, don't mix and match spaces and tabs. Use your editor to replace all tabs (search for \t in regex mode) with 4 spaces, and the code should work.

blhsing
  • 91,368
  • 6
  • 71
  • 106
  • Thanks. I'd give it a go – Trung Hà Jul 17 '18 at 11:10
  • I got it. Thanks. – Trung Hà Jul 17 '18 at 11:17
  • Since `flag += 1` belongs in the `for` loop, make sure you have it indented inside the `for` block with 4 spaces properly. – blhsing Jul 17 '18 at 11:19
  • Thanks. I fixed that indentation error. Now it says Invalid syntax at line 243, which goes like this: print num, " messages had been downloaded from today till - ",datetime.utcfromtimestamp(float(timestamp)/1000).strftime('%d-%m-%Y') The up arrow points at the Y. This is the only place in the code that this %d-%m-%y appears. How can I fix it? I know nothing about coding. It's just the code I found on the internet that helps me do my thing, that's all. So please excuse my ignorance :( – Trung Hà Jul 17 '18 at 11:25
  • That's a `print` statement that's available only to Python 2.7 or before. If you are running Python 3.x, convert it to a function by putting parentheses around the expression. `print(...)` – blhsing Jul 17 '18 at 11:28
  • 1
    Thank you so much. I just realized that all of those errors could be fixed by one step: install python 2.x instead of 3.x. I really appreciate your time. Have a good night :) – Trung Hà Jul 17 '18 at 11:49
-1

You should write the code to "Write the chunk to the file" under for loop. Please intend it under for loop:

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