[英]Python: TypeError: object of type 'NoneType' has no len(): Using JSON And rncryptor
from selenium import webdriver
import chromedriver_binary
import os, sys, inspect
import base64
import json
import rncryptor
import string
import random
letters = string.ascii_letters
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe() ))[0]))
cryptor = rncryptor.RNCryptor()
def init_driver():
chromedriver = os.path.join(current_folder,"chromedriver.exe")
driver = webdriver.Chrome(executable_path = chromedriver)
return driver
def editjson(location, value):
with open(os.path.join(current_folder,"config.json")) as f:
data = f.read()
d = json.loads(data)
d[location] = [value]
with open(os.path.join(current_folder,"config.json"), 'w') as f:
f.write(json.dumps(d))
def firstruntrue():
user = input("What is your Username? ")
password = input("What is your Password? ")
key = ''.join(random.choice(letters) for i in range(20))
editjson("key", key)
encrypted_user = cryptor.encrypt(user, key)
editjson("user", encrypted_user.decode('utf-8', 'ignore'))
encrypted_pass = cryptor.encrypt(password, key)
editjson("password", encrypted_pass.decode('utf-8', 'ignore'))
editjson("firstrun", "False")
with open(os.path.join(current_folder,"config.json"), "r") as handler:
info = json.load(handler)
user = info["user"]
password = info["password"]
firstrun = info["firstrun"]
#First Run
if "True" in firstrun:
firstruntrue()
#Reload after edit with firstrun()
with open(os.path.join(current_folder,"config.json"), "r") as handler:
info = json.load(handler)
user = info["user"]
password = info["password"]
firstrun = info["firstrun"]
key = info["key"]
#Chrome Script
if __name__ == "__main__":
user1 = cryptor.decrypt(user, key)
password1 = cryptor.decrypt(password, key)
driver = webdriver.Chrome()
driver.get(REDACTED)
User_box = driver.find_element_by_id(REDACTED)
User_box.send_keys(user1)
Password_box = driver.find_element_by_id(REDACTED)
Password_box.send_keys(password1)
search_box = driver.find_element_by_id(REDACTED)
search_box.submit()
sys.exit()
C:\Users\REDACTED\Desktop\REDACTED>python REDACTED.py
What is your Username? REDACTED
What is your Password? REDACTED
Traceback (most recent call last):
File "REDACTED.py", line 57, in <module>
user1 = cryptor.decrypt(user, key)
File "C:\Users\REDACTED\AppData\Roaming\Python\Python37\site-packages\rncryptor.py", line 104, in decrypt
n = len(data)
TypeError: object of type 'NoneType' has no len()
I get this error when I run this code.运行此代码时出现此错误。 What am I doing wrong?
我究竟做错了什么? Python 3.7
Python 3.7
Fill Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit.填充文本:Lorem ipsum dolor sit amet,consectetur adipiscing elit。 Cras vel consectetur augue.
Cras vel consectetur augue。 Morbi tristique enim lectus, nec aliquam ligula sagittis id.
Morbi tristique enim lectus,nec aliquam ligula sagittis id。 Aliquam erat volutpat.
Aliquam erat volutpat。 Sed ultricies porta odio, quis semper ex blandit et.
Sed ultricies porta odio、quis semper ex blandit 等。
from selenium import webdriver
import chromedriver_binary
import os, sys, inspect
import base64
import json
import rncryptor
import string
import random
letters = string.ascii_letters
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe() ))[0]))
cryptor = rncryptor.RNCryptor()
def init_driver():
chromedriver = os.path.join(current_folder,"chromedriver.exe")
driver = webdriver.Chrome(executable_path = chromedriver)
return driver
def editjson(location, value):
with open(os.path.join(current_folder,"config.json")) as f:
data = f.read()
d = json.loads(data)
d[location] = [value]
with open(os.path.join(current_folder,"config.json"), 'w') as f:
f.write(json.dumps(d))
def firstruntrue():
user = input("What is your Username? ")
password = input("What is your Password? ")
key = ''.join(random.choice(letters) for i in range(20))
editjson("key", key)
encrypted_user = cryptor.encrypt(user, key)
editjson("user", encrypted_user.decode('utf-8', 'ignore'))
encrypted_pass = cryptor.encrypt(password, key)
editjson("password", encrypted_pass.decode('utf-8', 'ignore'))
editjson("firstrun", "False")
with open(os.path.join(current_folder,"config.json"), "r") as handler:
info = json.load(handler)
user = info["user"]
password = info["password"]
firstrun = info["firstrun"]
#First Run
if "True" in firstrun:
firstruntrue()
#Reload after edit with firstrun()
with open(os.path.join(current_folder,"config.json"), "r") as handler:
info = json.load(handler)
user = info["user"]
password = info["password"]
firstrun = info["firstrun"]
key = info["key"]
#Chrome Script
if __name__ == "__main__":
user1 = cryptor.decrypt(user, key)
password1 = cryptor.decrypt(password, key)
driver = webdriver.Chrome()
driver.get(REDACTED)
User_box = driver.find_element_by_id(REDACTED)
User_box.send_keys(user1)
Password_box = driver.find_element_by_id(REDACTED)
Password_box.send_keys(password1)
search_box = driver.find_element_by_id(REDACTED)
search_box.submit()
sys.exit()
C:\Users\REDACTED\Desktop\REDACTED>python REDACTED.py
What is your Username? REDACTED
What is your Password? REDACTED
Traceback (most recent call last):
File "REDACTED.py", line 57, in <module>
user1 = cryptor.decrypt(user, key)
File "C:\Users\REDACTED\AppData\Roaming\Python\Python37\site-packages\rncryptor.py", line 104, in decrypt
n = len(data)
TypeError: object of type 'NoneType' has no len()
I get this error when I run this code.运行此代码时出现此错误。 What am I doing wrong?
我究竟做错了什么? Python 3.7
Python 3.7
Fill Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit.填充文本:Lorem ipsum dolor sit amet,consectetur adipiscing elit。 Cras vel consectetur augue.
Cras vel consectetur augue。 Morbi tristique enim lectus, nec aliquam ligula sagittis id.
Morbi tristique enim lectus,nec aliquam ligula sagittis id。 Aliquam erat volutpat.
Aliquam erat volutpat。 Sed ultricies porta odio, quis semper ex blandit et.
Sed ultricies porta odio、quis semper ex blandit 等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.