CoC server connection error when open a python file - python

I use Neovim with conquer of completion (CoC) and it works so good in all lenguages except python, when i try to open a python file it shows [coc] server connection lost. I have coc-pyright extension installed.

Related

Unable to create process

I updated my python version and when I try to run server on prompt for django I get this error.
Unable to create process using 'C:\Users\ALFRED\AppData\Local\Programs\Python\Python311\python.exe
manage.py runserver': The system cannot find the file specified.
This error occurs when the file system of the target device is corrupted or damaged, making your hard drive, USB or external hard drive inaccessible.
Are you sure you typed the right command python manage.py runserver.

Python 3.6 HTTP Server not reachable when compiled by PyInstaller on Windows

I created a web server in Python 3.6 using http.server.HTTPServer, http.server.SimpleHTTPRequestHandler and socketserver.ThreadingMixIn. It works as expected and I can access the webpage from any device on the local network.
I compiled it with PyInstaller to create a Windows executable. The webpage works with localhost, but it is not accessible from any device on the local network.
I used nmap from another device to scan the computer hosting the web server, and it appears that the port used by the webserver (8080) is open when I run my script normally (with the Python interpreter), and everything works. However, when I use the executable produced by PyInstaller the port isn't open and the webpage not reachable.
The executable doesn't produce any errors, and apart from that everything works.
I have tried to run the .exe file as administrator, and to this disable my antivirus/firewall. It doesn't work.
Here is my PyInstaller command :
pyinstaller --runtime-tmpdir "" --onefile -i icon.ico script.py
And here is the relevant code in my python file :
import http.server
import socketserver
port = 8080
class ThreadingSimpleServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
pass #using this so the webserver can handle mutliple requests at a time
class myWebServer(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
#does stuff
try:
server = ThreadingSimpleServer(('', port), myWebServer)
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down the program.')
server.socket.close()
I run your code and it works for me. The O.S. ask about opening the connection and everything seems to be ok. You must produce a log of some kind in order to let us understand what is going wrong. In my run i omit the -i switch because I don't have a .ico file.
Ok so I solved the issue but I still don't understand what caused it. Since the beginning I was building my script in a folder located in AppData : it wasn't working and I had no Windows firewall warning/confirmation showing up.
I moved my script to the Desktop and compiled it here : the Windows firewall confirmation showed up (this one) and the executable worked well.
I thought maybe the firewall might have flagged my program earlier and all the subsequent builds were blacklisted or something like that so I tried to compile the script in the original location, but this time I renamed it and I deleted all the files generated previously : it didn't work either (and no firewall confirmation/warning).
So now i'm pretty sure the error was caused by the firewall, and it had to do with the location from where the build was done, but I don't really understand why.

Python: Header line to use based on my python installation path

I am using xampp webserver for running my web service. I have installed python in my "D:\Software\Python34" local drive. My apache server is also running from "D:\Software\Xampp" drive only. So in my python file instead of the line,
#!/usr/bin/python
I tried using the line
#!/Software/Python34/python
But this throws error in the browser saying ,
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
couldn't create child process: 720003: test.py
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.7 (Win32) OpenSSL/0.9.8y PHP/5.4.25
What is the equivalent line for this in my case?
My code is simply,
#!python3
print ("Hello World!")
Without editing default environment variables in windows, we can just use the following shebang,
#!D:\Software\Python27\python
to run the piece of python code we have from any web service directory.

How to get Tor relay info via python + stem on linux?

I am trying to control tor on ubuntu linux using python's stem library as instructed on tor's website. However, when I ran the suggested python code
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate() # provide the password here if you set one
bytes_read = controller.get_info("traffic/read")
bytes_written = controller.get_info("traffic/written")
print "My Tor relay has read %s bytes and written %s." % (bytes_read, bytes_written)
I get the error:
Traceback (most recent call last):
File "littleRelay.py", line 5, in module
bytes_read = controller.get_info("traffic/read")
File "/usr/local/lib/python2.7/dist-packages/stem/control.py", line 852, in get_info
raise exc
stem.InvalidArguments: GETINFO request contained unrecognized keywords: traffic/read
So how can I get Tor relay info via python+stem on linux?
I think Tor is running fine because I started tor from the terminal and it says
[notice] Tor has successfully opened a circuit. Looks like client functionality is working.
[notice] Bootstrapped 100%: Done.
Furthermore, when I run the above python code, the terminal says
[notice] New control connection opened.
P.S. I have also tried the code on a windows pc and it worked. I'm really puzzled now.
That error indicates that Tor doesn't support the 'GETINFO traffic/read' query. This is odd - that is a feature I added to Tor back in 2011. Perhaps your copy of Tor is very, very out of date?
Problem Solved! Thank you Damian!
I uninstalled Tor on Ubuntu and install Tor again by following the detail guideline here. Now Tor works with the python code.
I'm not sure how exactly the problem arose but I suppose the problem had to do with installing Tor on Ubuntu by naively using
sudo apt-get install tor

How to run a remote Python program from Windows command prompt

I have an app on my website, and I run it with Python from the Windows Command Prompt.
When I try opening it like this,
python http://www.erickwilts.nl/apps/app.py
it says:
python: can't open file 'http://www.erickwilts.nl/apps/app.py': [Errno 22] Invalid argument
Is there a way I can do this?
Since the resource is located on webserver, you must download it first.
You can do it with urllib2
import urllib2
exec(urllib2.urlopen("http://www.erickwilts.nl/apps/app.py").read())
executing scripts like this is really dangerous though.
What I really wanted is to execute the file on the webserver itself. Luckily, I had help from some more experienced guys, who helped me on installing python on the webserver en executing my script from my own computer using ssh.

Categories