Questions tagged [typeerror]

A TypeError is a specific type of error raised when an operation or function is applied to an object of inappropriate type. You might encounter it in Python or JavaScript.

A TypeError often occurs during operations on two data types.

An example is given below, in which an attempt is made to add an integer to a string:

>>> 3 + "string"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>

Note that this behavior is not universal; some languages do not require two of the same data type to perform operations.

5623 questions
35
votes
6 answers

JS: Failed to execute 'getComputedStyle' on 'Window': parameter is not of type 'Element'

In short: I am trying to understand the meaning of this TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' The error appears while lunching Mediawiki's VisualEditor, as can be seen…
35
votes
2 answers

django: TypeError: 'tuple' object is not callable

Getting a type error, 'tuple' object is not callable. Any idea what it could be? (dont worry about the indentation. It copies in weird.) I'm trying to create choices based on PackSize of storeliquor. Views.py: def storeliquor(request, store_id,…
RuSs
  • 719
  • 2
  • 10
  • 25
34
votes
8 answers

TypeError: 'builtin_function_or_method' object is not subscriptable

elif( listb[0] == "-test"): run_all.set("testview") listb.pop[0] ERROR: Exception in Tkinter callback Traceback (most recent call last): File "/tools/python/2.7.2/lib/python2.7/lib-tk/Tkinter.py", line 1410, in call return…
Ani
  • 692
  • 1
  • 8
  • 22
34
votes
5 answers

Javascript .replaceAll() is not a function type error

The documentation page: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll let string = ":insertx: :insertx: :inserty: :inserty: :insertz: :insertz:"; let newstring = string.replaceAll(":insertx:",…
pyknight202
  • 502
  • 1
  • 3
  • 13
34
votes
1 answer

TypeError: a bytes-like object is required, not 'str' - python 2 to 3

Hi I am having trouble with this error message. I am new to Python and this Python2 and Python3 is a hassle. I'm not sure what to do here, the error message is as shown below. Using Ticker: AAPL Traceback (most recent call last): File…
Lasheen Lartey
  • 367
  • 2
  • 4
  • 8
32
votes
5 answers

Pandas: create named columns in DataFrame from dict

I have a dictionary object of the form: my_dict = {id1: val1, id2: val2, id3: val3, ...} I want to create this into a DataFrame where I want to name the 2 columns 'business_id' and 'business_code'. I tried: business_df =…
anonuser0428
  • 8,987
  • 18
  • 55
  • 81
31
votes
2 answers

Convert from '_io.BytesIO' to a bytes-like object in python3.6?

I am using this function to uncompress the body or a HTTP response if it is compressed with gzip, compress or deflate. def uncompress_body(self, compression_type, body): if compression_type == 'gzip' or compression_type == 'compress': …
Dan
  • 1,391
  • 3
  • 11
  • 29
31
votes
1 answer

Python TypeError: unsupported operand type(s) for ^: 'float' and 'int'

I wrote a simple program which approximates the evaluation of a definite integral using numerical integration. However, I am stumped when it comes to why I am getting the error in the title. Keep in mind that I haven't touched python in one and a…
Aris Pap
  • 313
  • 1
  • 3
  • 5
31
votes
5 answers

$(...).each is not a function

I'm trying to get the text inside all h2 tags on a page, using the web console. All I've found says to use each, I've tried var anArray = []; $('h2').each( function(i,e) { anArray.push($(e).innerHTML); }); But it returns TypeError:…
M. Sa
  • 351
  • 1
  • 3
  • 6
31
votes
5 answers

TypeError while using django rest framework tutorial

I am new to using Django Rest framework, i am following this tutorial Django-Rest-Framework Instead of snippets my model consists of a userprofile as given below: class UserProfile(models.Model): user = models.OneToOneField(User) …
Sirius
  • 706
  • 2
  • 9
  • 22
29
votes
4 answers

TypeError: list indices must be integers, not float

I have a python 3.x program that is producing an error: def main(): names = ['Ava Fischer', 'Bob White', 'Chris Rich', 'Danielle Porter', 'Gordon Pike', 'Hannah Beauregard', 'Matt Hoyle', 'Ross Harrison', 'Sasha Ricci',…
Dahaka
  • 295
  • 1
  • 4
  • 6
28
votes
4 answers

Python unsubscriptable

What does unsubscriptable mean in the context of a TypeError as in: TypeError: 'int' object is unsubscriptable EDIT: Short code example that results in this phenomena. a=[[1,2],[5,3],5,[5,6],[2,2]] for b in a: print b[0] > 1 > 5 > TypeError:…
Theodor
  • 4,937
  • 12
  • 38
  • 53
28
votes
2 answers

TypeError: coercing to Unicode: need string or buffer, int found

I have 2 APIs. I am fetching data from them. I want to assign particular code parts to string so that life became easier while coding. Here is the code: import urllib2 import json urlIncomeStatement = 'http://dev.c0l.in:8888' apiIncomeStatement =…
Marks Gniteckis
  • 463
  • 1
  • 6
  • 16
28
votes
2 answers

TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'

So I am VERY new to programming and I started with Python 3. I started reading "Learn Python the Hard Way". Now, I got to a point where I had this code: x = "There are %d types of people." % 10 binary = "binary" do_not = "don't" y = "Those who know…
user3586591
  • 289
  • 1
  • 3
  • 6
28
votes
1 answer

TypeError with ufunc bitwise_xor

In my program which traces out the path of a particle, I get the following error: Traceback (most recent call last): File "C:\Users\Felix\Google Drive\Research\particles.py", line 154, in bfield += b_X(r_p(r,pos[2]))*(r_p(r,pos[2])/r)…
doublefelix
  • 565
  • 1
  • 5
  • 19