-3

My Error is:

web.open("https://web.whatsapp.com/send?phone=" +lead+ "&text=" +message)
TypeError: can only concatenate str (not "float") to str

I am trying to automate the Whatsapp message and it shows this error. I am not able to understand what it means.

import pyautogui as pg
import webbrowser as web
import time
import pandas as pd
data = pd.read_csv("phone numbers.csv")
data_dict = data.to_dict('list')
leads = data_dict['Number']
messages = data_dict['Message']
combo = zip(leads,messages)
first = True
for lead,message in combo:
    time.sleep(4)
    web.open("https://web.whatsapp.com/send?phone="+lead+"&text="+message)
    if first:
        time.sleep(6)
        first=False
    width,height = pg.size()
    pg.click(width/2,height/2)
    time.sleep(8)
    pg.press('enter')
    time.sleep(8)
    pg.hotkey('ctrl', 'w')
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    Does this answer your question? [How do I put a variable inside a string?](https://stackoverflow.com/questions/2960772/how-do-i-put-a-variable-inside-a-string) – mkrieger1 Jan 20 '21 at 15:30

2 Answers2

0

You need to convert lead to it's string representation first:

web.open("https://web.whatsapp.com/send?phone="+str(lead)+"&text="+message)
couka
  • 1,361
  • 9
  • 16
0

The error you are seeing is because your leadvariable is a number, or float type of variable, not a string.

"Concatenate" is what you are trying to do with the + in the web.open line of code - you are generating a new string by adding multiple strings together.

However, Python doesn't allow you to concatenate a number or other non-string type to a string without explicitly converting it first.

web.open("https://web.whatsapp.com/send?phone="+str(lead)+"&text="+message)
Luke Storry
  • 6,032
  • 1
  • 9
  • 22