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
338
votes
7 answers

super() raises "TypeError: must be type, not classobj" for new-style class

The following use of super() raises a TypeError: why? >>> from HTMLParser import HTMLParser >>> class TextParser(HTMLParser): ... def __init__(self): ... super(TextParser, self).__init__() ... self.all_data = [] ... >>>…
Eric O Lebigot
  • 81,422
  • 40
  • 198
  • 249
237
votes
16 answers

TypeError: $ is not a function when calling jQuery function

I have a simple jQuery script in a WordPress plugin that is using a jQuery wrapper like this: $(document).ready(function(){ // jQuery code is in here }); I am calling this script from within the WordPress Dashboard and am loading it AFTER the…
Jason
  • 4,559
  • 12
  • 45
  • 56
220
votes
12 answers

TypeError: not all arguments converted during string formatting python

The program is supposed to take in two names, and if they are the same length it should check if they are the same word. If it's the same word it will print "The names are the same". If they are the same length but with different letters it will…
user2652300
  • 2,317
  • 2
  • 10
  • 3
181
votes
10 answers

"TypeError: (Integer) is not JSON serializable" when serializing JSON in Python?

I am trying to send a simple dictionary to a json file from python, but I keep getting the "TypeError: 1425 is not JSON serializable" message. import json alerts = {'upper':[1425],'lower':[576],'level':[2],'datetime':['2012-08-08 15:30']} afile =…
user1329894
  • 4,749
  • 4
  • 13
  • 7
173
votes
8 answers

Uncaught TypeError: (intermediate value)(...) is not a function

Everything works fine when I wrote the js logic in a closure as a single js file, as: (function(win){ //main logic here win.expose1 = .... win.expose2 = .... })(window) but when I try to insert a logging alternative function before that…
armnotstrong
  • 7,047
  • 10
  • 51
  • 108
160
votes
5 answers

TypeError: module.__init__() takes at most 2 arguments (3 given)

I have defined a class in a file named Object.py. When I try to inherit from this class in another file, calling the constructor throws an exception: TypeError: module.__init__() takes at most 2 arguments (3 given) This is my code: import…
lobjc
  • 2,249
  • 5
  • 18
  • 25
146
votes
3 answers

"Uncaught TypeError: Illegal invocation" in Chrome

When I use requestAnimationFrame to do some native supported animation with below code: var support = { animationFrame: window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || …
stefan
  • 2,217
  • 3
  • 13
  • 11
144
votes
4 answers

Python TypeError: not enough arguments for format string

Here's the output. These are utf-8 strings I believe... some of these can be NoneType but it fails immediately, before ones like that... instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname, procversion, int(percent), exe, description,…
y2k
  • 59,444
  • 25
  • 58
  • 84
135
votes
3 answers

TypeError: Cannot create a consistent method resolution order (MRO)

This is the code which I plan to use for my game, but it complains about an MRO error: class Player: pass class Enemy(Player): pass class GameObject(Player, Enemy): pass g = GameObject()
user188276
121
votes
6 answers

How to overcome TypeError: unhashable type: 'list'

I'm trying to take a file that looks like this: AAA x 111 AAB x 111 AAA x 112 AAC x 123 ... And use a dictionary to so that the output looks like this {AAA: ['111', '112'], AAB: ['111'], AAC: [123], ...} This is what I've tried file =…
Keenan
  • 1,389
  • 4
  • 11
  • 11
115
votes
16 answers

Javascript "Not a Constructor" Exception while creating objects

I am defining an object like this: function Project(Attributes, ProjectWidth, ProjectHeight) { this.ProjectHeight = ProjectHeight; this.ProjectWidth = ProjectWidth; this.ProjectScale = this.GetProjectScale(); this.Attributes =…
unni
  • 2,471
  • 3
  • 17
  • 21
93
votes
1 answer

If range() is a generator in Python 3.3, why can I not call next() on a range?

Perhaps I've fallen victim to misinformation on the web, but I think it's more likely just that I've misunderstood something. Based on what I've learned so far, range() is a generator, and generators can be used as iterators. However, this…
Jeff
  • 1,719
  • 2
  • 15
  • 19
63
votes
2 answers

"Series objects are mutable and cannot be hashed" error

I am trying to get the following script to work. The input file consists of 3 columns: gene association type, gene name, and disease name. cols = ['Gene type', 'Gene name', 'Disorder name'] no_headers = pd.read_csv('orphanet_infoneeded.csv',…
Sal
  • 651
  • 1
  • 5
  • 3
62
votes
4 answers

TypeError: coercing to Unicode: need string or buffer

This code returns the following error message: with open (infile, mode='r', buffering=-1) as in_f, open (outfile, mode='w', buffering=-1) as out_f: TypeError: coercing to Unicode: need string or buffer, file found # Opens each file to…
madkitty
  • 1,605
  • 6
  • 22
  • 37
56
votes
4 answers

str.translate gives TypeError - Translate takes one argument (2 given), worked in Python 2

I have the following code import nltk, os, json, csv, string, cPickle from scipy.stats import scoreatpercentile lmtzr = nltk.stem.wordnet.WordNetLemmatizer() def sanitize(wordList): answer = [word.translate(None, string.punctuation) for word in…
carebear
  • 691
  • 1
  • 7
  • 16
1
2 3
99 100