请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

4-11章节 执行报错:TypeError: object of type 'NoneType' has no len() ,不知道是什么原因

老师 不知道这个错是什么原因造成的,图片识别的代码可以运行,但按照4-11章节来运行,就会报错

--------------------------------------------------------
from page.register_page import Register_Page
from util.get_code import GetCode
class Register_Handle(object):

def __init__(self,driver):
self.driver = driver
self.register_p = Register_Page(self.driver)
def send_user_mail(self,email):
self.register_p.get_email_element().send_keys(email)
def send_user_name(self,name):
self.register_p.get_username_element().send_keys(name)
def send_user_password(self,password):
self.register_p.get_password_element().send_keys(password)

def send_user_code(self,filename):
get_code_text = GetCode(self.driver)
code = get_code_text.code_photo(filename)
self.register_p.get_code_element().send_keys(code)

def get_user_text(self,info,user_info):
try:
if info == 'user_email_error':
text = self.register_p.get_email_error_element().text
elif info == 'user_name_error':
text = self.register_p.get_name_error_element().text
elif info == 'user_password_error':
text = self.register_p.get_password_error_element().text
else:
text = self.register_p.get_code_error_elemenet().text
except:
text = None
return text
def click_register_button(self):
self.register_p.get_butten_element().click()

def get_register_text(self):
return self.register_p.get_butten_element().text

------------------------------------------------------
from handle.register_handle import Register_Handle

class Register_business(object):

def __init__(self,driver):
self.register_h = Register_Handle(driver)
def user_base(self,email,name,password,filename):
self.register_h.send_user_mail(email)
self.register_h.send_user_name(name)
self.register_h.send_user_password(password)
self.register_h.send_user_code(filename)
self.register_h.click_register_button()

def register_succes(self):
if self.register_h.get_register_text() == None:
return True
else:
return False
def login_email_error(self,email,name,password,filename):
self.user_base(email,name,password,filename)
if self.register_h.get_user_text('email_error',"请输入有效的电子邮件地址") == None:
return True
else:
return False
def login_username_error(self,email,name,password,filename):
self.user_base(email,name,password,filename)
if self.register_h.get_user_text('user_name_error',"字符长度必须大于等于4,一个中文字算2个字符") == None:
return True
else:
return False

def login_password_error(self,email,name,password,filename):
self.user_base(email,name,password,filename)
if self.register_h.get_user_text('user_password_error',"最少需要输入5个字符") == None:
return True
else:
return False

def login_code_error(self,email,name,password,filename):
self.user_base(email,name,password,filename)
if self.register_h.get_user_text('code_error',"验证码错误") == None:
return True
else:
return False

-----------------------------------------------------
from PIL import Image
from ShowapiRequest import ShowapiRequest
import time
class GetCode:
def __init__(self,driver):
self.driver = driver
def code_photo(self,filename):
self.driver.save_screenshot(filename)
element_code = self.driver.find_element_by_id("getcode_num")
left = element_code.location['x']
top = element_code.location['y']
right = element_code.size['width'] + left
height = element_code.size['height'] + top
im = Image.open(filename)
new_image = im.crop((left, top, right, height))
new_image.save(filename)
time.sleep(2)

def code_infor(self,filename):
self.code_photo(filename)
r = ShowapiRequest("http://route.showapi.com/184-4", "73290", "90d9d5556af84a7b8d2fe02047b92c7c")
r.addBodyPara("typeId", "35")
r.addBodyPara("convert_to_jpg", "0")
r.addFilePara("image", filename)
res = r.post()
print(res.text)
text = res.json()['showapi_res_body']['Result']
return text

https://img1.sycdn.imooc.com//szimg/5be82e7d0001deeb15890594.jpg

13886
收起

正在回答

1回答

'NoneType' has no len()  说明你拿这个list没有拿到,现在给你的是一个None对象。这个https://img1.sycdn.imooc.com//szimg/5be8e3400001ce6602890022.jpg仔细查一下元素时为正确,一步一步定位。

0 回复 有任何疑惑可以回复我~
  • 提问者 追风筝的人qym #1
    好的 明白了 我再检查检查 ,谢谢老师
    回复 有任何疑惑可以回复我~ 2018-11-12 10:49:00
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信