TypeError: can only concatenate str (not "int") to str
TL;DRYour Python code tried to join a piece of text (string) directly with a number (int) using the + sign, which Python does not allow.
Most likely cause: Using + to combine a string variable with an integer variable without first converting the integer to a string
Try first: Locate the exact line
Likely causes
- Using + to combine a string variable with an integer variable without first converting the integer to a stringmost likely
- A variable expected to hold text actually holds a number due to earlier code logicpossible
- Mixing data types from user input, file data, or API responses without explicit conversionless likely
How to fix it
Safest first: SafeChanges settingsDangerous
Locate the exact lineSafe
Run the script again and note the line number shown in the error traceback.
Inspect the variables on that lineSafe
Add print statements before the line to show the type and value of each variable involved in the concatenation.
Convert the number to textChanges settings
Change the code to use str(your_number) or an f-string like f"text {your_number}" instead of direct + concatenation.
If that didn't fix it
Add type checks with isinstance() around the concatenation to see which variable has the wrong type.
When to see a technician
If this error occurs inside a larger application you did not write, ask the original developer to review the data types being passed.
Quick answers
- What does TypeError: can only concatenate str (not "int") to str mean?
- Your Python code tried to join a piece of text (string) directly with a number (int) using the + sign, which Python does not allow.
- What causes TypeError: can only concatenate str (not "int") to str?
- Using + to combine a string variable with an integer variable without first converting the integer to a string. (most likely) A variable expected to hold text actually holds a number due to earlier code logic. (possible) Mixing data types from user input, file data, or API responses without explicit conversion. (less likely)
- How do I fix TypeError: can only concatenate str (not "int") to str?
- Try these in order, safest first: 1. Locate the exact line. 2. Inspect the variables on that line. 3. Convert the number to text.
- What if that didn't fix it?
- Add type checks with isinstance() around the concatenation to see which variable has the wrong type.
- When should I see a technician?
- If this error occurs inside a larger application you did not write, ask the original developer to review the data types being passed.
Related errors
codeTypeError: Failed to fetchcodeUncaught TypeError: Cannot read properties of null (reading 'addEventListener')codeTypeError: 'NoneType' object is not subscriptablecodeTypeError: Cannot read properties of undefined (reading 'map')codeERROR: Could not find a version that satisfies the requirement (from versions: none)codeerror: Your local changes to the following files would be overwritten by merge: Please commit your changes or stash them