简体   繁体   中英

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

Fill Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vel consectetur augue. Morbi tristique enim lectus, nec aliquam ligula sagittis id. Aliquam erat volutpat. Sed ultricies porta odio, quis semper ex blandit et.

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

Fill Text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vel consectetur augue. Morbi tristique enim lectus, nec aliquam ligula sagittis id. Aliquam erat volutpat. Sed ultricies porta odio, quis semper ex blandit et.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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