草庐IT

checked-exceptions

全部标签

Python - requests.exceptions.SSLError - dh key 太小

我正在使用Python和请求抓取一些内部页面。我已经关闭了SSL验证和警告。requests.packages.urllib3.disable_warnings()page=requests.get(url,verify=False)在某些服务器上,我收到无法通过的SSL错误。Traceback(mostrecentcalllast):File"scraper.py",line6,inpage=requests.get(url,verify=False)File"/cygdrive/c/Users/jfeocco/VirtualEnv/scraping/lib/python3.4/si

python - 为什么建议从 Exception 派生而不是 Python 中的 BaseException 类?

Python2documentation说“鼓励程序员从Exception类或其子类之一派生新的异常,而不是从BaseException”。没有进一步解释原因。我很好奇为什么会这样推荐?是否只是为了保留exceptionshierarchy正如Python开发人员所设想的那样?>>>dir(BaseException)==dir(Exception)True 最佳答案 从BaseException派生的异常是:GeneratorExit、KeyboardInterrupt、SystemExit。根据文档:GeneratorExit:

python - 其他选项而不是使用 try-except

当文本文件中的第2行有'nope'时,它将忽略该行并继续下一行。有没有不使用try和except的另一种写法?我可以使用ifelse语句来执行此操作吗?文本文件示例:0102nope1325nope代码:e=open('e.txt')alist=[]forlineine:start=int(line.split()[0])target=int(line.split()[1])try:ifline.split()[2]=='nope':continueexceptIndexError:alist.append([start,target]) 最佳答案

python异常<类型 'exceptions.ImportError'>没有名为gdb :的模块

我刚刚在运行linux的服务器计算机上从主目录中的源代码编译了gdb7.8。我之前一直在使用gdb7.6,除了gdb本身的稳定性问题(升级的原因)之外,一切正常。自从gdb升级后,当我运行cgdb0.6.7时,我立即收到以下消息:PythonExceptionNomodulenamedgdb:warning:CouldnotloadthePythongdbmodulefrom`/home/username/bin/gdb//python'.LimitedPythonsupportisavailablefromthe_gdbmodule.Suggestpassing--data-dire

python 3.5 类型提示 : can i check if function arguments match type hints?

python3.5是否提供允许测试给定的函数是否参数是否符合函数声明中给出的类型提示?如果我有这个函数:deff(name:List[str]):pass有没有python方法可以检查是否name=['a','b']name=[0,1]name=[]name=None...符合类型提示?我知道“运行时不会发生类型检查”,但我仍然可以检查在python中手动验证这些参数的有效性?或者如果python本身不提供该功能:我会使用什么工具需要用吗? 最佳答案 Python本身不提供此类函数,您可以阅读更多相关信息here:我为此写了一个装饰

Python 请求.exceptions.SSLError : EOF occurred in violation of protocol

我将从提供RESTfulJSONAPI的ABBG13网关检索一些信息。API通过https端点由网关托管。基本认证机制用于认证。然而所有的交通通过SSL层。在linux上使用命令:curl-s-k-XGET-uuser:passwordhttps://host/meters/a_serial/power一切顺利!我正在尝试使用Requests2.8.1和以下代码在Python2.7.10中为Windows编写脚本:importrequestsrequests.get('https://host/meters/a_serial/power',auth=('user','password'

python - Try-Except-Finally 语句的过时书籍描述

我正在关注Apress,从新手到专业的Python入门这本书。据说:finally.Youcanusetry/finallyifyouneedtomakesurethatsomecode(forexample,cleanupcode)isexecutedregardlessofwhetheranexceptionisraisedornot.Thiscodeisthenputinthefinallyclause.Notethatyoucannothavebothexceptclausesandafinallyclauseinthesametrystatement—butyoucanput

python - ImportError:无法从 sklearn.utils.validation 导入名称 check_array

当我从模块sklearn.utils.validation导入函数check_array时,出现导入错误(ImportError:cannotimportnamecheck_array).选项卡完成得到了check_arrays,但我想知道validation.py(sourcecodeonGithub)中只存在一个名为check_array的函数。此外,在scikit-learn/sklearn/cluster/spectral.py中实现的谱聚类算法还使用了from..utils.validationimportcheck_array,而不是check_arrays。我对此很困惑,

python - django.core.exceptions.ImproperlyConfigured : 'django_mongodb_engine' isn't an available database backend

我无法正确运行djangomongo引擎。我在settings.py中的数据库条目是DATABASES={'default':{'ENGINE':'django_mongodb_engine','NAME':'local',}}我的pipfreeze结果是Django==1.8.2django-mongodb-engine==0.5.2djangotoolbox==1.6.2pymongo==3.0.2运行时出错pythonmanage.pyrunserver是django.core.exceptions.ImproperlyConfigured:'django_mongodb_eng

python - 如何使用 Python Suds(版本 0.3.6)SOAP 库 : TypeNotFound exception? 导入 XSD 模式

我正在尝试将SABRE旅行Web服务与PythonSuds结合使用,但是一个XSD似乎格式不正确(可能在此架构中缺少命名空间)。fromsuds.clientimportClientwsdl='http://webservices.sabre.com/wsdl/sabreXML1.0.00/tpf/OTA_AirPriceLLSRQ.wsdl'client=Client(wsdl,cache=None)调试跟踪返回:.DEBUG:suds.wsdl:readingwsdlat:http://webservices.sabre.com/wsdl/sabreXML1.0.00/tpf/OT