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

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.

Related

Error No module named '_lzma' simpletransformers

I have model trained on colab and now I want to use that in my centOS7-server like this
import json
from flask import Flask, jsonify, request
import mysql.connector as mariadb
from simpletransformers.ner import NERModel,NERArgs
model = NERModel('bert', './checkpoint-14000', use_cuda= False)
model_args = NERArgs()
model_args.lazy_loading = True
app = Flask(__name__)
#app.route('/sp', methods=['POST'])
def addOne():
try:
prediction = model.predict([json.loads(request.data)['txt']])
return jsonify({'OK': prediction[0][0]})
except Exception as e:
return jsonify({'ERROR': e})
if __name__ == '__main__':
app.run(host='0.0.0.0')
I use python3.9
but I got the ERROR
Traceback (most recent call last):
File "/home/milad/flask/./wsgi.py", line 1, in <module>
from myproject import app
File "/home/milad/flask/./myproject.py", line 4, in <module>
from simpletransformers.ner import NERModel,NERArgs
File "/usr/local/lib/python3.9/site-packages/simpletransformers/ner/__init__.py", line 2, in <module>
from simpletransformers.ner.ner_model import NERModel
File "/usr/local/lib/python3.9/site-packages/simpletransformers/ner/ner_model.py", line 24, in <module>
from simpletransformers.ner.ner_utils import (
File "/usr/local/lib/python3.9/site-packages/simpletransformers/ner/ner_utils.py", line 33, in <module>
from datasets import load_dataset
File "/usr/local/lib/python3.9/site-packages/datasets/__init__.py", line 37, in <module>
from .arrow_dataset import Dataset, concatenate_datasets
File "/usr/local/lib/python3.9/site-packages/datasets/arrow_dataset.py", line 62, in <module>
from .arrow_reader import ArrowReader
File "/usr/local/lib/python3.9/site-packages/datasets/arrow_reader.py", line 29, in <module>
from .download.download_config import DownloadConfig
File "/usr/local/lib/python3.9/site-packages/datasets/download/__init__.py", line 9, in <module>
from .download_manager import DownloadManager, DownloadMode
File "/usr/local/lib/python3.9/site-packages/datasets/download/download_manager.py", line 29, in <module>
from ..utils.file_utils import cached_path, get_from_cache, hash_url_to_filename, is_relative_path, url_or_path_join
File "/usr/local/lib/python3.9/site-packages/datasets/utils/file_utils.py", line 30, in <module>
from .extract import ExtractManager
File "/usr/local/lib/python3.9/site-packages/datasets/utils/extract.py", line 3, in <module>
import lzma
File "/usr/local/lib/python3.9/lzma.py", line 27, in <module>
from _lzma import *
ModuleNotFoundError: No module named '_lzma'
I find my answer in this just look at the Solution

ValueError: source code string cannot contain null bytes while importing flask_wtf

I am trying to create forms for 'user registration' on a website. While trying to import flask_wtf module in Sublime Text 3 using the following input:
import flask_wtf
I am getting the following error:
Traceback (most recent call last):
File "C:\Users\Aadish\Desktop\Python Course Udemy\practice\Flask_blog\forms.py", line 1, in <module>
import flask_wtf
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\flask_wtf\__init__.py", line 3, in <module>
from .csrf import CSRFProtect, CsrfProtect
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\flask_wtf\csrf.py", line 11, in <module>
from wtforms import ValidationError
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\wtforms\__init__.py", line 11, in <module>
from wtforms import validators, widgets
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\wtforms\validators.py", line 9, in <module>
import email_validator
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\email_validator\__init__.py", line 6, in <module>
import dns.resolver
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\resolver.py", line 36, in <module>
import dns.message
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\message.py", line 24, in <module>
import dns.wire
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\wire.py", line 7, in <module>
import dns.name
File "C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\name.py", line 26, in <module>
import idna # type: ignore
ValueError: source code string cannot contain null bytes
It looks like your source files are messed up. Try to reinstall the dns library. If it does not help, manually edit the file C:\Users\Aadish\AppData\Local\Programs\Python\Python39\lib\site-packages\dns\name.py to fix the problem.

Whenever I run my discord bot using discord.py I'm getting an AttributeError 'logging' has no attribute 'getlogger'

All my code is on github except for the token.py file for obvious reasons.
bot.py file
I have had similar issues in the past and have resolved them by reconstructing some code so I apologize in advance if this is another one of those issues where I missed a capital or something but I have tried all the obvious syntax issues and none of them seemed to work. Atom also didn't show any errors.
Here is the whole error message:
Traceback (most recent call last):
File "C:\Users\james\Documents\botpy\bot.py", line 5, in <module>
import discord
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\__init__.py", line 21, in <module>
import logging
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\tokenize.py", line 34, in <module>
from token import *
File "C:\Users\james\Documents\botpy\token.py", line 2, in <module>
from discord.ext import commands
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\__init__.py", line 13, in <module>
from .bot import Bot, AutoShardedBot, when_mentioned, when_mentioned_or
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 27, in <module>
import asyncio
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\_base.py", line 42, in <module>
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)
Try to rename your file into main.py
I had a similar error just because the filename.

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.

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