简体   繁体   English

如何解决错误:for i in range(len(val)): TypeError: object of type 'NoneType' has no len() ,这可能很傻

[英]how to resolve Error : for i in range(len(val)): TypeError: object of type 'NoneType' has no len() , it might be silly

in my project i have to send a numpy board in Instagram dm , sendMessage() funtion works fine i can send str message but can not send that i have created by numpy , please help me在我的项目中,我必须在 Instagram dm 中发送一个 numpy 板, sendMessage()功能工作正常我可以发送 str 消息但无法发送我创建的 numpy,请帮助我

THANKS in advance提前致谢

My Code我的代码

from time import sleep
import numpy as np
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\saksh\\Desktop\\codeing\\Projects\\Connect 4\\chrome profiles\\chrome profile - 1")
browser = webdriver.Chrome(options =  options , executable_path = r"C:\Users\saksh\Desktop\codeing\imported items\chromedriver v-90.exe")


ROW_COUNT = 6
COLUMN_COUNT = 7

def create_board():
    board = np.zeros((ROW_COUNT, COLUMN_COUNT))

    return board


def send_board(board):
    board = str(np.flip(board, 0))
    board  = board.replace("0", "🔳")
    board = board.replace("1", "🟢")
    board =  board.replace("2", "⚫")
    

board = create_board()


def sendMessage(message , browser):
    message_box = browser.find_element_by_css_selector(".ItkAi > textarea:nth-child(1)")
    message_box.send_keys(message)
    message_box.Keys.ENTER 

# manually go u any instagram dm 
# manually go u any instagram dm 
print("manually go u any instagram dm , and press enter") 

input("press enter !!")

sleep(5)

sendMessage(send_board(board) , browser)

ERROR错误

raceback (most recent call last): File "c:\\Users\\saksh\\Desktop\\codeing\\Projects\\Connect 4\\temp1.py", line 46, in sendMessage(send_board(board) , browser) File "c:\\Users\\saksh\\Desktop\\codeing\\Projects\\Connect 4\\temp1.py", line 35, in sendMessage message_box.send_keys(message) File "C:\\Users\\saksh\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py", line 478, in send_keys {'text': "".join(keys_to_typing(value)), File "C:\\Users\\saksh\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\selenium\\webdriver\\common\\utils.py", line 150, in keys_to_typing for i in range(len(val)): TypeError: object of type 'NoneType' has no len() Raceback(最近一次通话):文件“c:\\Users\\saksh\\Desktop\\codeing\\Projects\\Connect 4\\temp1.py”,第 46 行,在 sendMessage(send_board(board) , browser) 文件“c:\\Users \\saksh\\Desktop\\codeing\\Projects\\Connect 4\\temp1.py”,第 35 行,在 sendMessage message_box.send_keys(message) 文件“C:\\Users\\saksh\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site -packages\\selenium\\webdriver\\remote\\webelement.py", line 478, in send_keys {'text': "".join(keys_to_typing(value)), File "C:\\Users\\saksh\\AppData\\Local\\Programs\\ Python\\Python39\\lib\\site-packages\\selenium\\webdriver\\common\\utils.py", line 150, in keys_to_typing for i in range(len(val)): TypeError: object of type 'NoneType' has no len()

From the error trace it's quite clear that in this block从错误跟踪很明显,在这个块中

def sendMessage(message , browser):
    message_box = browser.find_element_by_css_selector(".ItkAi > textarea:nth-child(1)")
    message_box.send_keys(message)
    message_box.Keys.ENTER 

This line这条线

message_box.send_keys(message)

fails since the message is of NoneType .失败,因为messageNoneType
That means that you passing there a NoneType object.这意味着您传递了一个NoneType对象。
This is because you are calling this method by这是因为您通过以下方式调用此方法

sendMessage(send_board(board) , browser)

but the send_board method doesn't return a value / object.send_board方法不返回值/对象。
So you actually send nothing, NoneType object to sendMessage method as a message to be inserted into the message_box element.所以你实际上什么都不发送, NoneType对象到sendMessage方法作为要插入到message_box元素的消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 for i in range(len(val)): TypeError: object of type 'numpy.float64' has no len() - for i in range(len(val)): TypeError: object of type 'numpy.float64' has no len() 对于我在range(len(val))中:TypeError:类型为'numpy.int64'的对象没有len() - for i in range(len(val)): TypeError: object of type 'numpy.int64' has no len() 如何修复“ TypeError:类型为'NoneType'的对象没有len()”? - How do I fix “TypeError: object of type 'NoneType' has no len()”? 一个 len(list) 给出 TypeError: object of type 'NoneType' has no len() - A len(list) gives TypeError: object of type 'NoneType' has no len() Python-TypeError:“ NoneType”类型的对象没有len() - Python - TypeError: object of type 'NoneType' has no len() TypeError:'NoneType'类型的对象没有len() - TypeError: object of type 'NoneType' has no len() Python TypeError:“NoneType”类型的对象没有 len() - Python TypeError: object of type 'NoneType' has no len() Python TypeError: (“'NoneType' 类型的对象没有 len()” - Python TypeError: (“object of type 'NoneType' has no len()” Python:TypeError:'NoneType' 类型的对象没有 len() - Python: TypeError: object of type 'NoneType' has no len() 解决方案:TypeError: object of type 'NoneType' has no len() - Solution for: TypeError: object of type 'NoneType' has no len()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM