So I am trying to follow a tutorial online on how to work with web.py, and I got it installed but unfortunately, using this piece of code yields a nasty error.
My Code...
import web
urls = (
'/(.*)', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self, name):
return "Hello", name, '. How are you today?'
if __name__== "__main__":
app.run()
MY ERROR:
C:\Users\User\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/User/PycharmProjects/Webprojects/main.py
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Webprojects/main.py", line 15, in <module>
app.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\application.py", line 312, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\wsgi.py", line 59, in runwsgi
return httpserver.runsimple(func, server_addr)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\httpserver.py", line 154, in runsimple
func = LogMiddleware(func)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\httpserver.py", line 296, in __init__
from BaseHTTPServer import BaseHTTPRequestHandler
ModuleNotFoundError: No module named 'BaseHTTPServer'
Process finished with exit code 1
That import line won't work in Python 3 which moved BaseHTTPServer to http.server
In your specific case you should update web.py to the current version that works with Python 3.
Related
I was just learning socket programming in python and was unable to run my socket commands in vs code.
the code i wrote is:-
import socket
import threading
PORT=5050
SERVER =socket.gethostbyname(socket.gethostname)
print(SERVER)
The code produces this error:
Traceback (most recent call last):
File "c:\Users\Gurkirat Singh\Desktop\tempCodeRunnerFile.py", line 1, in <module>
import socket
File "c:\Users\Gurkirat Singh\Desktop\socket.py", line 3, in <module>
from xmlrpc.client import Server
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\xmlrpc\client.py", line 136, in <module>
import http.client
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\http\client.py",
line 789, in <module>
class HTTPConnection:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\http\client.py",
line 837, in HTTPConnection
def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
AttributeError: partially initialized module 'socket' has no attribute '_GLOBAL_DEFAULT_TIMEOUT' (most likely due to a circular import)
Looking at your stack trace, you seem to have a file named socket.py:
File "c:\Users\Gurkirat Singh\Desktop\socket.py", line 3, in <module>
from xmlrpc.client import Server
Having a file named socket.py in your workspace causes import problems because Python won't import its library module socket but instead will import your own file.
Rename your file from socket.py to something else like mysock.py and delete anything from your Desktop directory called socket.pyc if it exists.
I am getting an error when trying to run a python script in Linux. I am trying to run a Firewall configuration converter I have dowloaded from here:
https://github.com/glennake/DirectFire_Converter
(converter.py file)
First I was getting an error related to logger, but after running a pip3 install logger it has been fixed. Now I am getting NameError: name 'logging' is not defined, despite of code looking good as far I know. For some reason, it looks like this line is not working:
logger = logging.getLogger(__name__)
But I am seeing that all modules are being imported properly. Any idea about what is bringing the issue? Thanks.
full error traceback:
Traceback (most recent call last):
File "converter1.py", line 257, in <module>
main(src_format=args.source, dst_format=args.destination, routing_info=args.routing)
File "/home/ubuntu/.local/lib/python3.8/site-packages/traceback_with_variables/print.py", line 98, in wrapper
return func(*args, **kwargs)
File "converter1.py", line 233, in main
parsed_data = parse(
File "converter1.py", line 107, in parse
from DirectFire.Converter.parsers.ciscoasa_pre83 import parse
File "/home/ubuntu/DirectFire_Converter/DirectFire/Converter/parsers/ciscoasa_pre83.py", line 23, in <module>
logger = logging.getLogger(__name__)
NameError: name 'logging' is not defined
You need to import, add import logging at the top of your file
This question already has answers here:
Python Error: io.UnsupportedOperation: fileno
(2 answers)
Closed 4 years ago.
I am new to Flask (and quite new to python) and I have tried running the following very basic script:
from flask import Flask
app= Flask(__name__)
#app.route('/')
def home():
return "This is the homepage"
if __name__=="__main__":
app.run(debug=True)
I am using Python 3.6 and IDLE on Windows 10.
The problem is I keep getting the following error:
Traceback (most recent call last):
File "C:/Users/Susy/Desktop/provaflask.py", line 7, in <module>
app.run(debug=True)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 936, in run
cli.show_server_banner(self.env, self.debug, self.name, False)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\cli.py", line 630, in show_server_banner
click.echo(message)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\utils.py", line 217, in echo
file = _default_text_stdout()
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\_compat.py", line 621, in func
rv = wrapper_func()
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\_compat.py", line 385, in get_text_stdout
rv = _get_windows_console_stream(sys.stdout, encoding, errors)
File "C:\Users\Susy\AppData\Local\Programs\Python\Python36\lib\site-packages\click\_winconsole.py", line 261, in _get_windows_console_stream
func = _stream_factories.get(f.fileno())
io.UnsupportedOperation: fileno
From this question, the problem seems to be related to the use of IDLE, however I would like to keep using it, so can you please help? Thank you!
As you can find out here
You have to run your script from straight up Python instead.
You have to save that file for example in app.py
and run from your command line:
python app.py
or in your exmaple:
python C:/Users/Susy/Desktop/provaflask.py
I am trying to write a script that will start an new engine.
Using some code from IPython source I have:
[engines.py]
def make_engine():
from IPython.parallel.apps import ipengineapp as app
app.launch_new_instance()
if __name__ == '__main__':
make_engine(file='./profiles/security/ipcontroller-engine.json', config='./profiles/e2.py')
if I run this with python engines.py in the command line I run into a configuration problem and my traceback is:
Traceback (most recent call last):
File "engines.py", line 30, in <module>
make_engine(file='./profiles/security/ipcontroller-engine.json', config='./profiles/e2.py')
File "engines.py", line 20, in make_engine
app.launch_new_instance(**kwargs)
File "/Users/martin/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 562, in launch_instance
app = cls.instance(**kwargs)
File "/Users/martin/anaconda/lib/python2.7/site-packages/IPython/config/configurable.py", line 354, in instance
inst = cls(*args, **kwargs)
File "<string>", line 2, in __init__
File "/Users/martin/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 94, in catch_config_error
app.print_help()
File "/Users/martin/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 346, in print_help
self.print_options()
File "/Users/martin/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 317, in print_options
self.print_alias_help()
File "/Users/martin/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 281, in print_alias_help
cls = classdict[classname]
KeyError: 'BaseIPythonApplication'
if I do a super ugly hack like the following, it works:
def make_engine():
from IPython.parallel.apps import ipengineapp as app
app.launch_new_instance()
if __name__ == '__main__':
from sys import argv
argv = ['--file=./profiles/security/ipcontroller-engine.json', '--config=./profiles/e2.py'] #OUCH this is ugly!
make_engine()
Why can't I pass the keyword arguments in the launch_new_instance method?
What are the right keyword arguments?
Where can I get the entry point to entering my configuration options?
Thanks,
Martin
The way to instantiate a new ipengine using the IPEngineApp api is:
def make_engine():
from IPython.parallel.apps.ipengineapp import IPEngineApp
lines1 ="a_command()"
app1 = IPEngineApp()
app1.url_file = './profiles/security/ipcontroller-engine.json'
app1.cluster_id = 'e2'
app1.startup_command = lines1
app1.init_engine()
app1.start()
However, this starts a new ipengine process that takes control of the script execution process, so there is no way I can start multiple engines in the same script using this method.
Thus I had to fallback on the subprocess module to spawn all additional new ipengines:
import subprocess
import os
pids = []
for num in range(1,3):
args = ["ipengine", "--config", os.path.abspath("./profiles/e%d.py" % num), "--file",os.path.abspath( "./profiles/security/ipcontroller-engine.json") ]
pid = subprocess.Popen(args).pid
pids.append(pid)
I've tried to make my own server to new sync service in FireFox.
I used the following tutorial: https://docs.services.mozilla.com/howtos/run-sync-1.5.html .
When I wanted to check it by using make test I got the following error:
Traceback (most recent call last):
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/nose/loader.py", line 403, in loadTestsFromName
module = resolve_name(addr.module)
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/nose/util.py", line 311, in resolve_name
module = __import__('.'.join(parts_copy))
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/syncstorage/__init__.py", line 5, in <module>
import mozsvc.config
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/mozsvc/config.py", line 10, in <module>
from konfig import Config, SettingsDict
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/konfig/__init__.py", line 11, in <module>
from configparser import ConfigParser, ExtendedInterpolation
ImportError: cannot import name ExtendedInterpolation
What's happened?
configparser.ExtendedInterpolation does not exist in Python 2.
You need to use Python 3.