AttributeError: 'module' object has no attribute 'SSL_ST_INIT' [duplicate] - python

This question already has answers here:
Python AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
(23 answers)
Closed 5 years ago.
I am getting an SSL error using twilio. Anybody have any suggestions?
Error:
Traceback (most recent call last):
File "communication_easy/that_guy/communicate.py", line 4, in <module>
from twilio.rest import Client
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/__init__.py", line 14, in <module>
from twilio.http.http_client import TwilioHttpClient
File "/usr/local/lib/python2.7/dist-packages/twilio/http/http_client.py", line 1, in <module>
from requests import Request, Session, hooks
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 84, in <module>
from urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 118, in <module>
SSL_ST_INIT = _lib.SSL_ST_INIT
AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
Code:
import random
from twilio.rest import Client
TWILIO_ACCOUNT_SID = "asdfasdfsdfsdf"
TWILIO_AUTH_TOKEN = "asdfasdfasdfasf"
TWILIO_NUMBER = "+5555555"
def send_text(body, target_phone_number):
client = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
message = client.messages.create(body=body, from_=TWILIO_NUMBER, to=target_phone_number)
send_text(blah, blah)

According to this github ticket, the problem can be solved by upgrading to pyOpenSSL>=16.2.0
Try:
pip install pyOpenSSL -U

Related

LocalProxy.__init__() got an unexpected keyword argument 'unbound_message'

I'm trying to build my application, after installing flask_login0.4.1 and configuring it
i come across this error
Traceback (most recent call last):
File "C:\Users\Catalyst\Desktop\Python\chatAp\application.py", line 2, in <module>
from wtform_fields import *
File "C:\Users\Catalyst\Desktop\Python\chatAp\wtform_fields.py", line 6, in <module>
from models import User
File "C:\Users\Catalyst\Desktop\Python\chatAp\models.py", line 2, in <module>
from flask_login import UserMixin
File "C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\flask_login\__init__.py", line 16, in <module>
from .login_manager import LoginManager
File "C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\flask_login\login_manager.py", line 24, in <module>
from .utils import (_get_user, login_url as make_login_url, _create_identifier,
File "C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\flask_login\utils.py", line 13, in <module>
from werkzeug.security import safe_str_cmp
ImportError: cannot import name 'safe_str_cmp' from 'werkzeug.security' (C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\werkzeug\security.py)
based on answers on stackoverflow I have downgraded werkzeug to 2.0.0 but i got other error
Traceback (most recent call last):
File "C:\Users\Catalyst\Desktop\Python\chatAp\application.py", line 1, in <module>
from flask import Flask, render_template,redirect,url_for
File "C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\flask\__init__.py", line 4, in <module>
from . import json as json
File "C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\flask\json\__init__.py", line 8, in <module>
from ..globals import current_app
File "C:\Users\Catalyst\Desktop\Python\chatAp\venv\lib\site-packages\flask\globals.py", line 56, in <module>
app_ctx: "AppContext" = LocalProxy( # type: ignore[assignment]
TypeError: LocalProxy.__init__() got an unexpected keyword argument 'unbound_message'
what other alternatives solutions I can use
I'm using flask 2.2.2
Try
Werkzeug <= 2.1.2
flask == 2.1.2
Both of these have to be compatible. Let me know if you can work it out. the above version worked for me.

AttributeError: module 'tensorflow.python.ops.linalg.linear_operator_util' has no attribute 'matmul_with_broadcast'

I am trying to create my own PyEnvironment for TF-Agents.
However, this error keeps showing up:
AttributeError: module 'tensorflow.python.ops.linalg.linear_operator_util' has no attribute 'matmul_with_broadcast'
I have found out that this seems to be an issue with tensorflow-probability, but I have installed the version tensorflow-probability=0.7.0 recommended at
https://github.com/tensorflow/agents/issues/91
I have tried reinstalling and updating
tensorflow-gpu=2.0.0-beta1
tf-agents-nightly
tensorflow-probability=0.7.0
Here is a minimal code example:
from tf_agents.environments import py_environment
class myEnv(py_environment.PyEnvironment):
def __init__(self):
pass
def _reset(self):
pass
def _step(self, action):
pass
This is the full error message when running this minimum example:
Traceback (most recent call last): File ".\env_mwe.py", line 1, in <module>
from tf_agents.environments import py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\__init__.py", line 18, in <module>
from tf_agents.environments import batched_py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\batched_py_environment.py", line 33, in <module>
from tf_agents.environments import py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\py_environment.py", line 29, in <module>
from tf_agents.trajectories import time_step as ts File "C:\Python37\lib\site-packages\tf_agents\trajectories\__init__.py", line 19, in <module>
from tf_agents.trajectories import time_step File "C:\Python37\lib\site-packages\tf_agents\trajectories\time_step.py", line 28, in <module>
from tf_agents.specs import array_spec File "C:\Python37\lib\site-packages\tf_agents\specs\__init__.py", line 20, in <module>
from tf_agents.specs.distribution_spec import DistributionSpec File "C:\Python37\lib\site-packages\tf_agents\specs\distribution_spec.py", line 22, in <module>
import tensorflow_probability as tfp File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\__init__.py", line 78, in <module>
from tensorflow_probability.python import * # pylint: disable=wildcard-import File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\__init__.py", line 22, in <module>
from tensorflow_probability.python import distributions File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\distributions\__init__.py", line 64, in <module>
from tensorflow_probability.python.distributions.linear_gaussian_ssm import LinearGaussianStateSpaceModel File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\distributions\linear_gaussian_ssm.py", line 41, in <module>
_matmul = linear_operator_util.matmul_with_broadcast AttributeError: module 'tensorflow.python.ops.linalg.linear_operator_util' has no attribute 'matmul_with_broadcast'
Found it!
In order to use tensorflow-gpu with tensorflow-probability, one needs to install tfp-nightly
So pip3 install --upgrade tfp-nightly did the trick
To use 2.0.0beta1 requires tfp-nightly.

numpy “object has no atrribute ”open“” [duplicate]

This question already has answers here:
numpy "object has no atrribute "open"" [duplicate]
AttributeError: 'module' object has no attribute 'open'
(2 answers)
Closed 2 years ago.
I tried running some old pygame code which uses the surfarray class, and hence, numpy. I got this error, does anyone know why and what to do to to fix it? I have tried re-installing numpy but am still seeing this.
File "Titles.py", line 1, in <module>
import pygame
File "/usr/local/lib/python2.7/dist-packages/pygame/__init__.py", line 346, in <module>
import pygame.surfarray
File "/usr/local/lib/python2.7/dist-packages/pygame/surfarray.py", line 72, in <module>
import pygame._numpysurfarray as numpysf
File "/usr/local/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 51, in <module>
import numpy
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 23, in <module>
from .npyio import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 14, in <module>
from ._datasource import DataSource
File "/usr/lib/python2.7/dist-packages/numpy/lib/_datasource.py", line 220, in <module>
_file_openers = _FileOpeners()
File "/usr/lib/python2.7/dist-packages/numpy/lib/_datasource.py", line 162, in __init__
self._file_openers = {None: io.open}
AttributeError: 'module' object has no attribute 'open'

Python AttributeError: 'module' object has no attribute 'get'

I installed the requests package, but when I start to use it, I got this error :
AttributeError: 'module' object has no attribute 'get'
This my code :
from bs4 import BeautifulSoup
import requests
r = requests.get("http://someSite.com/path")
I checked some solution to this problem, and most of them saying that either there is a mistake with importing the package, or that a file with the name requests.py exist in the current directory, but it's not the case for me.
it's been a while since I got this error, and I stuck with it.
any idea? thanks.
UPDATE
FULL error message
Traceback (most recent call last):
File "parser.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 47, in <module>
from cryptography import x509
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/base.py", line 14, in <module>
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.py", line 14, in <module>
from cryptography.hazmat.backends.interfaces import RSABackend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
import pkg_resources
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 76, in <module>
import parser
File "/home/lichiheb/Desktop/parser.py", line 4, in <module>
r = requests.get("http://t...content-available-to-author-only...s.com/search-results-jobs/?searchId=1483197031.949&action=search&page=1&view=list")
AttributeError: 'module' object has no attribute 'get'
Your file is called parser.py which conflicts with a built-in module name parser.
The error message about requests was a weird and unfortunate coincidence. Just rename your module to something else.

Weird behaviour with tweepy in Python?

I have python 2.7.9 on OS X (10.11). I have installed tweepy 3.5.0 and simplejson 3.8.1. When i write a program (IDE: textWrangler) for updating status of twitter account (by using tweepy) and run the program using command line it throws error on "import tweepy" in a program. However when i run the same code on python shell, it execute sucessfuly (without any error). Any suggestions or comments?
Traceback (most recent call last):
File "tweepytesting.py", line 1, in <module>
import tweepy
File "build/bdist.macosx-10.6-intel/egg/tweepy/__init__.py", line 14, in <module>
File "build/bdist.macosx-10.6-intel/egg/tweepy/api.py", line 12, in <module>
File "build/bdist.macosx-10.6-intel/egg/tweepy/binder.py", line 11, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 33, in <module>
from .packages.ssl_match_hostname import CertificateError
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/packages/__init__.py", line 3, in <module>
from . import ssl_match_hostname
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py", line 3, in <module>
from ssl import CertificateError, match_hostname
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 90, in <module>
import textwrap
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 40, in <module>
class TextWrapper:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 82, in TextWrapper
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans'
If I add this line:
import string; print(string)
just above import tweepy, then the following is printed:
<module 'string' from '/Users/yasirmuhammad/Desktop/learnpython/string.pyc'>

Categories

Resources