Tag: typeerror

TypeError:exception必须是旧式的类或派生自BaseException,而不是str

以下是我的代码: test = 'abc' if True: raise test + 'def' 而当我运行这个,它给了我TypeError TypeError: exceptions must be old-style classes or derived from BaseException, not str 那么test应该是什么types?

json.dump抛出“TypeError:{…}是不是JSON序列化”看似有效的对象?

背景 :我正在写一个应该pipe理我的音乐文件的Python程序。 它抓取目录,并将文件和它们的元数据(通过mutagen)编码成JSON格式,作为一个简单的“数据库”。 我有目录search很好,但是当我尝试保存数据库,或编码为JSON,它会引发“TypeError:{…}不是JSON可序列化”(…是一些字典和键值,下面更多) 问题 :程序按照以下格式构build一个大的字典对象: { "<song id>":{ "artist":"<song artist>", "album":"<song album>", "title":"<song title>"}, … } 每一首歌曲文件都通过这种格式进行索引。 当我尝试将数据库转储到一个文件,我得到这个: Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> sit() File "D:\workbench\ideas\musicmanager\v0\spider.py", line 116, in sit json.dump(js.db,f,True) File "C:\Python27\lib\json\__init__.py", line 181, in dump for chunk in iterable: File "C:\Python27\lib\json\encoder.py", line 428, in _iterencode for […]

Uncaught TypeError:Object#<Object>没有方法'moveBoxes'

我试图使用我的asp.net mvc网站的moveBoxes插件,它不工作(显然)。 我在我的head标签中导入了像这样的site.master中的movingboxes.js <script src="<%: Url.Content("~/Scripts/jquery.movingboxes.js")%>" type="text/javascript"></script> 浏览器成功获取这个脚本。 现在我有一个常规的观点,从site.masterinheritance了这个jQuery的一点点,它调用了moveBoxes插件 <script type="text/javascript"> $(document).ready(function () { $($('#slider-one')); $('#slider-one').movingBoxes({ startPanel: 1, panelWidth: .5, fixedHeight: false }); $('#slider-two').movingBoxes({ startPanel: 1, panelWidth: .5, fixedHeight: false }); }); </script> 当我查看页面。 每一件事情都很好(包括其他的jQuery的东西),除了这个插件,我得到这个错误 这里是错误的描述 任何帮助,将不胜感激 编辑 所以显然我有这个: <script type="text/javascript" src="../../Scripts/jquery-1.4.1.js" /> <script src="<%: Url.Content("~/Scripts/jquery.movingboxes.js")%>" type="text/javascript"></script> 现在通过将其更改为: <script type="text/javascript" src="../../Scripts/jquery-1.4.1.js"></script> <script src="<%: Url.Content("~/Scripts/jquery.movingboxes.js")%>" type="text/javascript"></script>

TypeError:强制为Unicode:需要string或缓冲区

此代码返回以下错误消息: 在out_f中打开(infile,mode ='r',buffering = -1)in_f,open(outfile,mode ='w',buffering = -1)TypeError:强制为Unicode:需要string或缓冲区,find文件 # Opens each file to read/modify infile=open('110331_HS1A_1_rtTA.result','r') outfile=open('2.txt','w') import re with open (infile, mode='r', buffering=-1) as in_f, open (outfile, mode='w', buffering=-1) as out_f: f = (i for i in in_f if i.rstrip()) for line in f: _, k = line.split('\t',1) x = re.findall(r'^1..100\t([+-])chr(\d+):(\d+)\.\.(\d+).+$',k) if not x: continue […]

Javascript“不是构造函数”exception,同时创build对象

我正在定义一个像这样的对象: function Project(Attributes, ProjectWidth, ProjectHeight) { this.ProjectHeight = ProjectHeight; this.ProjectWidth = ProjectWidth; this.ProjectScale = this.GetProjectScale(); this.Attributes = Attributes; this.currentLayout = ''; this.CreateLayoutArray = function() {….} } 然后我尝试创build和实例如下所示: var newProj = new Project(a,b,c); 但是这个执行被抛出: Project is not a constructor 什么可能是错的? 我search了很多,但仍然无法弄清楚我做错了什么。

正则expression式的Pythontypes错误

所以,我有这样的代码: url = 'http://google.com' linkregex = re.compile('<a\s*href=[\'|"](.*?)[\'"].*?>') m = urllib.request.urlopen(url) msg = m.read() links = linkregex.findall(msg) 但是,然后python返回这个错误: links = linkregex.findall(msg) TypeError: can't use a string pattern on a bytes-like object 我做错了什么?

在Python中序列化JSON时,“TypeError:(Integer)不是JSON序列化”?

我想发送一个简单的字典从Python的JSON文件,但我不断收到“TypeError:1425不是JSON序列化”消息。 import json alerts = {'upper':[1425],'lower':[576],'level':[2],'datetime':['2012-08-08 15:30']} afile = open('test.json','w') afile.write(json.dumps(alerts,encoding='UTF-8')) afile.close() 如果我添加默认参数,然后写入,但整数值作为string写入JSON文件,这是不可取的。 afile.write(json.dumps(alerts,encoding='UTF-8',default=str))

Python TypeError:格式string没有足够的参数

这是输出。 这些是utf-8string,我相信…其中一些可以是NoneType,但它会立即失败,之前像那样… instr = "'%s', '%s', '%d', '%s', '%s', '%s', '%s'" % softname, procversion, int(percent), exe, description, company, procurl TypeError:格式string没有足够的参数 7的7虽然?

TypeError:不是在string格式化python过程中转换的所有参数

程序应该有两个名字,如果长度相同,应该检查它们是否是相同的单词。 如果它是相同的单词,它将打印“名称是相同的” 。 如果长度相同但字母不同,则会打印“名称不同但长度相同” 。 我有一个问题的部分是在底部的4行。 #!/usr/bin/env python # Enter your code for "What's In (The Length Of) A Name?" here. name1 = input("Enter name 1: ") name2 = input("Enter name 2: ") len(name1) len(name2) if len(name1) == len(name2): if name1 == name2: print ("The names are the same") else: print ("The names are different, […]

Chrome中的“Uncaught TypeError:非法调用”

当我使用requestAnimationFrame来做一些原生支持的animation和下面的代码: var support = { animationFrame: window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame }; support.animationFrame(function() {}); //error support.animationFrame.call(window, function() {}); //right 直接调用support.animationFrame会给… Uncaught TypeError:非法调用 在Chrome中。 为什么?