I have deployed Flask Server on IIS. I'm getting below error while importing IPython module in my code.
I have tried IPython version: 5.0, 6.0, 7.16.3 but still
When i run my code through cmd it works and server on localhost starts. But when hosted through IIS Server below issue remains If I keep import IPython line in code.
My python config:
python 3.6
Flask==1.1.2
Keras==2.1.3
scikit-learn==0.23.2
scipy==1.4.1
tensorflow==1.14.0
wfastcgi==3.0.0
Heres my code:
from flask import Flask
import IPython
app = Flask(__name__)
#app.route("/flaskapi2/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
Error:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "E:\deploy_car_damage\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "E:\deploy_car_damage\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "E:\deploy_car_damage\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\main.py", line 2, in <module>
import IPython
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\__init__.py", line 56, in <module>
from .terminal.embed import embed
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\terminal\embed.py", line 15, in <module>
from IPython.core.interactiveshell import DummyMod, InteractiveShell
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\core\interactiveshell.py", line 63, in <module>
from IPython.utils import io
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 94, in <module>
stdin = IOStream(sys.stdin, fallback=devnull)
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 38, in __init__
for meth in filter(clone, dir(stream)):
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 37, in clone
return not hasattr(self, meth) and not meth.startswith('_')
File "E:\deploy_car_damage\venv36\lib\site-packages\IPython\utils\io.py", line 81, in closed
return self.stream.closed
ValueError: underlying buffer has been detached
StdOut:
StdErr:
What does underlying buffer has been detached mean and how can I resolve it.
Related
While following a Flask tutorial I stumbled around this very strange problem! While setting up the Migrate directory , after the first step of setting the flask app using set FLASK_APP=sql1.py, when I ran this command flask db init I got this error:
(first_flask_env) C:\Users\aakash\Desktop\python programs>flask db init
Traceback (most recent call last):
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\aakash\Anaconda3\envs\first_flask_env\Scripts\flask.exe\__main__.py", line 7, in <module>
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 557, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\click\core.py", line 1061, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\click\core.py", line 1100, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 500, in get_command
self._load_plugin_commands()
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask\cli.py", line 496, in _load_plugin_commands
self.add_command(ep.load(), ep.name)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\pkg_resources\__init__.py", line 2472, in load
return self.resolve()
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\pkg_resources\__init__.py", line 2478, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\flask_migrate\__init__.py", line 8, in <module>
from alembic import __version__ as __alembic_version__
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\__init__.py", line 8, in <module>
from . import op # noqa
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\op.py", line 1, in <module>
from .operations.base import Operations
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\operations\__init__.py", line 1, in <module>
from .base import Operations, BatchOperations
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\operations\base.py", line 3, in <module>
from .. import util
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\util\__init__.py", line 6, in <module>
from .pyfiles import ( # noqa
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\alembic\util\pyfiles.py", line 6, in <module>
from mako.template import Template
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\template.py", line 10, in <module>
from mako.lexer import Lexer
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\lexer.py", line 11, in <module>
from mako import parsetree, exceptions, compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\parsetree.py", line 9, in <module>
from mako import exceptions, ast, util, filters, compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\exceptions.py", line 11, in <module>
from mako import util, compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\util.py", line 11, in <module>
from mako import compat
File "c:\users\aakash\anaconda3\envs\first_flask_env\lib\site-packages\mako\compat.py", line 124, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
I'm getting the exact same error while running my .py script also,here's the script:
from flask import Flask
import os
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
basedir = os.path.abspath(os.path.dirname(__file__)) #Full directory path of the file I'm working with..here, sql1.py
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
Migrate(app,db) #Here it connect the application "app.py"
# with the database "db"
class puppy(db.Model):
__tablename__ = 'Name Provided by me!!'
id = db.Column(db.Integer,primary_key = True)
name = db.Column(db.Text)
age = db.Column(db.Integer)
def __init__(self,name,age):
self.name = name
self.age = age
def __repr__(self):
return f"puppy {self.name} is {self.age} year/s old!"
I looked into every solution I found (here and this)and made sure everything was correct! I ran this command when my environment was activated which had installed every package needed including SQLAlchemy and Flask-Migrate.
I even deleted them (packages) and re-installed their latest versions but still getting the same error!
I'm using Python 3.8.5
You have some dependencies that are too old and incompatible with Python 3.8. At the very least, you should update the mako package:
pip install --upgrade mako
I had a similar issue I had to update flask_sqlalchemy even after doing this I had issues. I ended up having to make a new virtual environment, I would make a small hello world project on another virtual environment to see if that works.
For me, it was giving the same error, so I removed __init__.py file from the folder which has app.py
After removing I ran the
flask init db
it worked :)
I have foolishly reinstalled all my Python 2.7 dependencies and it's broken something. If you notice on line 1, os.uname() has a valid value, but by the time GAE calls ctypes module (line 3), it has been emptied and my local server won't respond to the client.
This feels a bit over my head & I'd appreciate any guidance.
os.uname() is: 19.3.0
INFO 2020-03-04 19:11:42,584 instance.py:294] Instance PID: 8624
os.uname() is:
ERROR 2020-03-04 19:11:43,311 wsgi.py:269]
Traceback (most recent call last):
File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 311, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 96, in LoadObject
__import__(cumulative_path)
File "/Users/dgaedcke/dev/TouchstoneMicroservices/service_backend/main.py", line 7, in <module>
import endpoints as google_cloud_endpoints
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/endpoints/__init__.py", line 29, in <module>
from .api_config import api, method
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/endpoints/api_config.py", line 44, in <module>
import attr
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/__init__.py", line 5, in <module>
from . import converters, exceptions, filters, validators
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/filters.py", line 7, in <module>
from ._compat import isclass
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/_compat.py", line 139, in <module>
set_closure_cell = make_set_closure_cell()
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/_compat.py", line 129, in make_set_closure_cell
ctypes = import_ctypes()
File "/Users/dgaedcke/dev/TouchstoneMicroservices/lib/site-packages/attr/_compat.py", line 95, in import_ctypes
import ctypes
File "/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 29, in <module>
if int(_os.uname()[2].split('.')[0]) < 8:
ValueError: invalid literal for int() with base 10: ''
attrs hasn't been using ctypes since 19.2.0, so the solution is to get your dependencies somehow updated.
Try editing the stubs file located within the devappserver2/python/runtime.
google_appengine/google/appengine/tools/devappserver2/python/runtime/stubs.py
From:
def fake_uname():
"""Fake version of os.uname."""
return ('Linux', '', '', '', '')
To:
def fake_uname():
"""Fake version of os.uname."""
return ('Linux', 'local', '19', 'Darwin Kernel Version 19', 'x86_64')
It isn’t a great long term solution because updates to the gcloud tool chain will likely wipe out the changes.
I am getting syntax error when i try to run my py file.
Traceback (most recent call last):
File "/home/ubuntu/environment/run.py", line 2, in <module>
from flask import Flask
File "/home/ubuntu/.local/lib/python3.6/site-packages/flask/__init__.py", line 14, in <module>
from jinja2 import escape
File "/home/ubuntu/.local/lib/python3.6/site-packages/jinja2/__init__.py", line 82, in <module>
_patch_async()
File "/home/ubuntu/.local/lib/python3.6/site-packages/jinja2/__init__.py", line 78, in _patch_async
from jinja2.asyncsupport import patch_all
File "/home/ubuntu/.local/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 13, in <module>
import asyncio
File "/usr/lib/python3.6/asyncio/__init__.py", line 21, in <module>
from .base_events import *
File "/usr/lib/python3.6/asyncio/base_events.py", line 17, in <module>
import concurrent.futures
File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/usr/local/lib/python2.7/dist-packages/concurrent/futures/_base.py", line 414
raise exception_type, self._exception, self._traceback
^
SyntaxError: invalid syntax
The code causing this problem is as follows:
import os
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello():
return "Hello World"
if __name__ == '__main__':
app.run(host=os.environ.get('IP'),
port=int(os.environ.get('PORT')),
debug=True)
I try to print a ticket in a thermal printer. I use module escpos
but when I run the script in Windows it sends me the following error
Traceback (most recent call last):
File "C:\Users\Angel\Desktop\Escritorio\impreimer.py", line 5, in <module>
Epson = printer.Usb(0x1a86,0x7584,1)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\escpos\printer.py", line 51, in __init__
self.open()
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\escpos\printer.py", line 68, in open
self.device.detach_kernel_driver(0)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\usb\core.py", line 1077, in detach_kernel_driver
interface)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\site-packages\usb\backend\libusb0.py", line 606, in detach_kernel_driver
_check(_lib.usb_detach_kernel_driver_np(dev_handle, intf))
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\ctypes\__init__.py", line 361, in __getattr__
func = self.__getitem__(name)
File "C:\Users\Angel\AppData\Local\Programs\Python\Python36\lib\ctypes\__init__.py", line 366, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'usb_detach_kernel_driver_np' not found
[Finished in 0.5s with exit code 1]
and this is my code:
import sys
from escpos import *
pr = printer.Usb(0x1a86,0x7584)
How can i fix this?
try this.
pr = printer.Usb(0x1a86,0x7584, interface=0, in_ep=0x82, out_ep=0x02)
if you are using Windows you need use programs like zadig or LibusbK and install filters.
https://zadig.akeo.ie/
http://libusbk.sourceforge.net/UsbK3/index.html
I've noticed that whenever I enable the database settings on my django project (starting to notice a trend in my questions?) it gives me an internal server error. Setting the database settings to be blank makes the error go away. Here are the apache error logs that it outputs.
mod_wsgi (pid=770): Exception occurred processing WSGI script '/Users/teifionjordan/rob2/apache/django.wsgi'.
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/core/handlers/wsgi.py", line 239, in __call__
response = self.get_response(request)
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py", line 67, in get_response
response = middleware_method(request)
File "/Library/Python/2.5/site-packages/django/contrib/sessions/middleware.py", line 9, in process_request
engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
File "/Library/Python/2.5/site-packages/django/contrib/sessions/backends/db.py", line 2, in <module>
from django.contrib.sessions.models import Session
File "/Library/Python/2.5/site-packages/django/contrib/sessions/models.py", line 4, in <module>
from django.db import models
File "/Library/Python/2.5/site-packages/django/db/__init__.py", line 16, in <module>
backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
File "/Library/Python/2.5/site-packages/django/db/backends/mysql/base.py", line 10, in <module>
import MySQLdb as Database
File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 4, in __bootstrap__
File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 841, in resource_filename
self, resource_name
File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 1310, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 1332, in _extract_resource
self.egg_name, self._parts(zip_path)
File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 921, in get_cache_path
self.extraction_error()
File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 887, in extraction_error
raise err
ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 20] Not a directory: '/Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp'
The Python egg cache directory is currently set to:
/Library/WebServer/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
And here is the django.wsgi file
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'rob2.settings'
sys.path.append('/Users/teifionjordan')
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I have several other scripts that all connect to a mysql database just fine, if I run the tutorial server then it displays the admin panel correctly. I have tried changing the environ variables for eggs but still nothing changes.
You need to set the PYTHON_EGG_CACHE environment variable. Apache/mod_wsgi is trying to extract the egg into a directory that Apache doesn't have write access to....or that doesn't exist.
It's explained in the Django docs here.
Does /Library/WebServer/.python-eggs exist? What does your Apache config file look like?