GVKun编程网logo

AttributeError:“模块”对象在Python 2.7.11中没有属性“ PROTOCOL_TLSv1_2”(python对象没有这个属性)

5

以上就是给各位分享AttributeError:“模块”对象在Python2.7.11中没有属性“PROTOCOL_TLSv1_2”,其中也会对python对象没有这个属性进行解释,同时本文还将给你拓

以上就是给各位分享AttributeError:“模块”对象在Python 2.7.11中没有属性“ PROTOCOL_TLSv1_2”,其中也会对python对象没有这个属性进行解释,同时本文还将给你拓展AtributeError:“模块”对象没有属性“ plt”-Seaborn、AttributeError:“ numpy.float64”对象在时间戳记中没有属性“ year”、AttributeError:“ tuple”对象没有属性“ encode”-MySQLdb Python、AttributeError:“ _ AppCtxGlobals”对象在Flask中没有属性“ user”等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

AttributeError:“模块”对象在Python 2.7.11中没有属性“ PROTOCOL_TLSv1_2”(python对象没有这个属性)

AttributeError:“模块”对象在Python 2.7.11中没有属性“ PROTOCOL_TLSv1_2”(python对象没有这个属性)

我在Mac上获取对python安装的tls v1.2支持时遇到问题。

这是我的openssl版本:

openssl versionOpenSSL 1.0.2h  3 May 2016

这是我的python版本:

python --versionPython 2.7.11

这是我测试的方式:

>>> import ssl>>> ssl.PROTOCOL_TLSv1_2Traceback (most recent call last):  File "<stdin>", line 1, in <module>AttributeError: ''module'' object has no attribute ''PROTOCOL_TLSv1_2''

阅读:https :
//docs.python.org/2/library/ssl.html
它说:

由于对操作系统套接字API进行了调用,因此某些行为可能取决于平台。安装的OpenSSL版本也可能导致行为变化。例如,TL​​Sv1.1和TLSv1.2随附openssl版本1.0.1。

因此,我在安装OpenSSL 1.0.2h时对tlsv1.2支持有要求。

谁有想法?

答案1

小编典典

问题是python使用的openssl版本不支持TLS 1.2。

我用brew安装了openssl,然后重新安装了python,告诉它使用我通过brew安装的openssl:

$ brew update$ brew install openssl$ brew install python --with-brewed-openssl

然后一切正常!

AtributeError:“模块”对象没有属性“ plt”-Seaborn

AtributeError:“模块”对象没有属性“ plt”-Seaborn

我对这些库非常陌生,在绘制此图时遇到了麻烦:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import random

df5 = pd.read_csv('../../../../datos/tiempos-exacto-variando-n-m0.csv',sep=',',engine='python')
print(df5)
df5['n'] = df5['n'].apply(lambda x: x**2)
sns.jointplot(df5['n'],df5['tiempoTotal'],kind="reg")
sns.plt.show()

我得到这个输出:

 n  m  tiempoTotal
0      1  0         2274
1      2  0         3370
2      3  0         5709
3      4  0         8959
4      5  0        13354
5      6  0        18503
6      7  0        26329
7      8  0        33859
8      9  0        41110
9     10  0        52710
10    11  0        64364
11    12  0        74142
12    13  0        81072
13    14  0        69332
14    15  0        71027
15    16  0        89721
16    17  0        85459
17    18  0        95217
18    19  0       119210
19    20  0       136888
20    21  0       131903
21    22  0       138395
22    23  0       151222
23    24  0       163542
24    25  0       177236
25    26  0       192475
26    27  0       240162
27    28  0       260701
28    29  0       235752
29    30  0       250835
..   ... ..          ...
580  581  0     88306854
581  582  0     89276420
582  583  0     87457875
583  584  0     90807004
584  585  0     87790003
585  586  0     89821530
586  587  0     89486585
587  588  0     88496901
588  589  0     89090661
589  590  0     89110803
590  591  0     90397942
591  592  0     94029839
592  593  0     92749859
593  594  0    105991135
594  595  0     95383921
595  596  0    105155207
596  597  0    114193414
597  598  0     98108892
598  599  0     97888966
599  600  0    103802453
600  601  0     97249346
601  602  0    101917488
602  603  0    104943847
603  604  0     98966140
604  605  0     97924262
605  606  0     97379587
606  607  0     97518808
607  608  0     99839892
608  609  0    100046492
609  610  0    103857464

[610 rows x 3 columns]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-63146953b89d> in <module>()
      9 df5['n'] = df5['n'].apply(lambda x: x**2)
     10 sns.jointplot(df5['n'],kind="reg")
---> 11 sns.plt.show()

AttributeError: 'module' object has no attribute 'plt'

我在我这运行Jupyter Notebook使用Python 2.7.12。有任何想法吗?

AttributeError:“ numpy.float64”对象在时间戳记中没有属性“ year”

AttributeError:“ numpy.float64”对象在时间戳记中没有属性“ year”

如何解决AttributeError:“ numpy.float64”对象在时间戳记中没有属性“ year”?

我有一个数据框,其中有一个名为CRASH TIME的列,其中包含一个日期时间对象,但是由于导入,根据df.info(),它现在包含一系列dtype object。 / p>

我正在尝试使用apply()函数创建一个包含该系列每年圣诞节日期的列:

df.apply(lambda x: dt.datetime(x[''CRASH TIME''].year,12,25),axis=1)

这将产生错误AttributeError: ''numpy.float64'' object has no attribute ''year''。 因此,对于类型为x[''CRASH TIME'']的{​​{1}}对象,我决定尝试:

numpy.float64

现在会产生错误df.apply(lambda x: dt.datetime(x[''CRASH TIME''].astype(''datetime64'').year,axis=1) 。似乎它被识别为AttributeError: ''Timestamp'' object has no attribute ''astype''或TimeStamp,并且似乎无法决定哪个,从而难以诊断或正确float64

我在做什么错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

AttributeError:“ tuple”对象没有属性“ encode”-MySQLdb Python

AttributeError:“ tuple”对象没有属性“ encode”-MySQLdb Python

我正在用MySQL编写Python代码。

我的数据库架构如下:

-------------
| id | name |
-------------
|    |      |
|    |      |

以下是我的代码的一部分:

cursor = self.conn.cursor()
query = ("SELECT name FROM TABLENAME WHERE id = '%s'",(str(id.decode('unicode_escape').encode('ascii','utf-8'),)))
cursor.execute(query)

我正在通过URL传递ID。

并得到以下错误:

AttributeError:“元组”对象没有属性“ encode”

在查询中对ID的值进行硬编码时,会得到结果。但是由于某些原因,当我传递参数时它不起作用。

AttributeError:“ _ AppCtxGlobals”对象在Flask中没有属性“ user”

AttributeError:“ _ AppCtxGlobals”对象在Flask中没有属性“ user”

@app.route(''/login'', methods = [''GET'', ''POST''])@oid.loginhandlerdef login():    if g.user is not None and g.user.is_authenticated():        return redirect(url_for(''index''))    form = LoginForm()    if form.validate_on_submit():        session[''remember_me''] = form.remember_me.data        return oid.try_login(form.openid.data, ask_for = [''nickname'', ''email''])    return render_template(''login.html'',         title = ''Sign In'',        form = form,        providers = app.config[''OPENID_PROVIDERS''])

但是,这给了我一个AttributeError,我将在下面粘贴StackTrace。这完全是我从示例来源中粘贴的错误。我确实使用PeeWee代替了SQLAlchemy,但是由于这段代码对数据库没有任何作用,但是我不知道为什么会这样。

有人知道我在这里做错什么吗?

Traceback (most recent call last):  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__    return self.wsgi_app(environ, start_response)  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app    response = self.make_response(self.handle_exception(e))  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception    reraise(exc_type, exc_value, tb)  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app    response = self.full_dispatch_request()  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request    rv = self.handle_user_exception(e)  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception    reraise(exc_type, exc_value, tb)  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request    rv = self.dispatch_request()  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request    return self.view_functions[rule.endpoint](**req.view_args)  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/flask_openid.py", line 446, in decorated    return f(*args, **kwargs)  File "/Users/kramer65/dev/repos/microblog/app/views.py", line 31, in login    if g.user is not None and g.user.is_authenticated():  File "/Users/kramer65/dev/repos/microblog/flask/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__    return getattr(self._get_current_object(), name)AttributeError: ''_AppCtxGlobals'' object has no attribute ''user''

答案1

小编典典

g.user全局
如果你要注意的话,你会记得在登录视图功能中我们检查g.user以确定用户是否已经登录。要实现此目的,我们将使用before_requestFlask中的事件。before_request每次接收到请求时,所有装饰有功能的函数都会在查看函数之前运行。因此,这是设置g.user变量(文件app/views.py)的正确位置:

@app.before_requestdef before_request():    g.user = current_user

这就是全部。在current_user全球是由瓶,登录设置,所以我们只要把复制的g对象有更好的访问。这样,所有请求都可以访问登录的用户,甚至在模板内部也可以。

你的代码显然缺少此before_request处理程序。

我们今天的关于AttributeError:“模块”对象在Python 2.7.11中没有属性“ PROTOCOL_TLSv1_2”python对象没有这个属性的分享已经告一段落,感谢您的关注,如果您想了解更多关于AtributeError:“模块”对象没有属性“ plt”-Seaborn、AttributeError:“ numpy.float64”对象在时间戳记中没有属性“ year”、AttributeError:“ tuple”对象没有属性“ encode”-MySQLdb Python、AttributeError:“ _ AppCtxGlobals”对象在Flask中没有属性“ user”的相关信息,请在本站查询。

本文标签: