我正在使用pyVmomi在Python2.6中编写脚本,并使用其中一种连接方法:
service_instance = connect.SmartConnect(host=args.ip,
user=args.user,
pwd=args.password)
Run Code Online (Sandbox Code Playgroud)
我收到以下警告:
/usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py:734: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
InsecureRequestWarning)
Run Code Online (Sandbox Code Playgroud)
有趣的是,我没有使用pip安装urllib3(但它位于/usr/lib/python2.6/site-packages/requests/packages/urllib3/).
我按照这里的建议尝试过
import urllib3
...
urllib3.disable_warnings()
Run Code Online (Sandbox Code Playgroud)
但这并没有改变任何事情.
我一直这样:
DeprecationWarning: integer argument expected, got float
Run Code Online (Sandbox Code Playgroud)
如何让这条消息消失?有没有办法避免Python中的警告?
安装BeautifulSoup之后,每当我在cmd中运行我的Python时,就会出现这个警告.
D:\Application\python\lib\site-packages\beautifulsoup4-4.4.1-py3.4.egg\bs4\__init__.py:166:
UserWarning: No parser was explicitly specified, so I'm using the best
available HTML parser for this system ("html.parser"). This usually isn't a
problem, but if you run this code on another system, or in a different
virtual environment, it may use a different parser and behave differently.
To get rid of this warning, change this:
BeautifulSoup([your markup])
to this:
BeautifulSoup([your markup], "html.parser")
Run Code Online (Sandbox Code Playgroud)
我没有理解为什么它出来以及如何解决它.
我在python脚本中隐藏了一些简单的数学,并得到以下警告:
"警告:划分为零除以".
为了提供一些背景,我拿着两个值,并试图找到价值的百分比差值(a - b) / a,如果它超过一定的范围内,那么对其进行处理,但有时值a或b为零.
我想摆脱这个特定的警告(在一个特定的行),但到目前为止我找到的所有信息似乎告诉我如何停止所有警告(我不想要).
当我以前编写shell脚本时,我可以做这样的事情
code...
more code 2 > error.txt
even more code
Run Code Online (Sandbox Code Playgroud)
在那个例子中,我会得到'代码'和'甚至更多代码'命令的警告,但不是第二行.
这可能吗?
我有统计问题的功能:
import numpy as np
from scipy.special import gamma as Gamma
def Foo(xdata):
...
return x1 * (
( #R is a numpy vector
( ((R - x2)/beta) ** (x3 -1) ) *
( np.exp( - ((R - x2) / x4) ) ) /
( x4 * Gamma(x3))
).real
)
Run Code Online (Sandbox Code Playgroud)
有时我会从shell获得以下警告:
RuntimeWarning: divide by zero encountered in...
Run Code Online (Sandbox Code Playgroud)
我使用numpy isinf函数来纠正其他文件中函数的结果,所以我不需要这个警告.
有没有办法忽略这条消息?换句话说,我不希望shell打印此消息.
我不想禁用所有python警告,只是这个.
PyCharm在代码样式,约定和逻辑陷阱上提供了一些有用的警告.如果我尝试提交带有警告(或错误)的代码,它也会提供通知.
有时我会有意识地忽略特定代码行的这些警告(出于各种原因,通常要考虑第三方库的实现细节).我想要压制警告,但只是为了那条线(如果警告出现在我不是故意的另一条线上,我想知道它!)
我怎么能在PyCharm中做到这一点?(遵循通用Python约定非常可取.)
我正在玩编码和解码,但我从sklearn得到这个错误:
警告(来自警告模块):文件"C:\ Python36\lib\site-packages\sklearn\preprocessing\label.py",第151行,如果是diff:DeprecationWarning:空数组的真值是不明确的.返回False,但将来会导致错误.使用
array.size > 0检查数组不为空.
这是完整的代码,你可以在python 3+中自己运行它
我的问题是为什么它说我使用一个空数组,因为我显然不在我的代码中,谢谢你花时间回答我的问题.
### label encoding ###
import numpy as np
from sklearn import preprocessing
# Sample input labels
input_labels = ["red", "black", "red", "green",\
"black", "yellow", "white"]
# Create label encoder abd fit the label
encoder = preprocessing.LabelEncoder()
encoder.fit(input_labels)
# Print the mapping
print("\nLabel mapping:")
for i, item in enumerate(encoder.classes_):
print(item, "-->", i)
# Encode a set of labels using encoder
test_labels = ["green", "red", "black"]
encoded_values = encoder.transform(test_labels)
print("\nLabels =", test_labels) …Run Code Online (Sandbox Code Playgroud) 我有一些python代码,在某些时候,采用轴的方式是一个合理稀疏的数组与nans in.每次我运行代码它引发一个RuntimeWarning.
我知道是什么导致了警告,这是故意的,并且它不会影响输出.然而,每次运行程序时都会发出警告是非常恼人的 - 那么,是否有一种廉价且令人讨厌的方法来防止它们被打印到终端?
我正在将一个遗留项目切换为自动生成 alembic 迁移,它有一些 sqlalchemy 无法识别的索引。当我运行时,alembic revision --autogenerate migration_name会创建一个空迁移(因为我已经解决了所有其他不一致问题),但我收到 8 个警告,例如:
/project/.venv/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/base.py:3328: SAWarning: Skipped unsupported reflection of expression-based index idx_name
"expression-based index %s" % idx_name
Run Code Online (Sandbox Code Playgroud)
在 postgres 中,我查找索引定义,如下所示:
/project/.venv/lib/python3.6/site-packages/sqlalchemy/dialects/postgresql/base.py:3328: SAWarning: Skipped unsupported reflection of expression-based index idx_name
"expression-based index %s" % idx_name
Run Code Online (Sandbox Code Playgroud)
读完这篇文章后,我尝试在模型定义之后添加索引并添加到__table_args__ .
mydb=# SELECT tablename, indexdef FROM pg_indexes WHERE schemaname = 'public' AND indexname = 'idx_name';
tablename | indexdef
-----------+-------------------------------------------------------------------------------
plan | CREATE UNIQUE INDEX idx_name ON public.plan USING btree (lower((name)::text))
(1 row) …Run Code Online (Sandbox Code Playgroud) 每次使用Flask Security时都会收到警告.
FlaskWTFDeprecationWarning: "flask_wtf.Form" has been renamed to "FlaskForm"
and will be removed in 1.0.
Run Code Online (Sandbox Code Playgroud)
这是Flask Security的问题还是我可以解决的问题?我正在使用Flask-Security == 1.7.5
from flask_security import current_user, login_required, RoleMixin, Security, \
SQLAlchemyUserDatastore, UserMixin, utils
Run Code Online (Sandbox Code Playgroud)
我似乎没有直接导入Flask_WTF.
python ×9
numpy ×2
warnings ×2
arrays ×1
deprecated ×1
flask ×1
ignore ×1
postgresql ×1
pycharm ×1
python-2.6 ×1
python-3.x ×1
pyvmomi ×1
scikit-learn ×1
sqlalchemy ×1
urllib3 ×1
user-warning ×1