簡體   English   中英

Python:TypeError:“NoneType”類型的 object 沒有 len():使用 JSON 和 rncryptor

[英]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()

運行此代碼時出現此錯誤。 我究竟做錯了什么? Python 3.7

填充文本: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 等。

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()

運行此代碼時出現此錯誤。 我究竟做錯了什么? Python 3.7

填充文本: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 等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM