I'm calling speedtest.py from my python program in order to run a speed test.
After importing speedtest.py I create a speedtest object using
s = speedtest.Speedtest()
servers = s.get_best_server()
then run upload/download tests.
This has been working, but recently it has been failing.
I found if I just ran speedtest from the cli, I'd get a 403 forbidden error.
I then read than Speedtest now requires the use of secure servers.
SO, if from the cli I type
speedtest --secure
it runs perfectly.
My question is:
How can I tell speedtest to use secure servers from my python program?
I've tried variations of
s = speedtest.Speedtest("secure")
and
servers = s.get_best_server("secure")
I haven't used the Python API for speedtest-cli, but looking at the source, Speedtest() has a secure parameter which presumably makes it require secure servers. So you'd just need to specify it when instantiating the class:
s = speedtest.Speedtest(secure=True)
BTW, there is documentation for the Python API, but it's super barebones and doesn't mention this parameter at all.
Related
I have developed a Python web server using Flask, and some of the endpoints make use of the subprocess module to call different executables. On development, using the Flask debug server, everything works fine. However, when running the server along with nginx+WSGI (on the exact same machine), some subprocess calls fail.
For example, one of the tools I'm using is Microsoft's dotnet, which I installed from my user as sudo apt-get install -y aspnetcore-runtime-5.0 and is then called from Python with the subprocess module. When I run the server with python3 server.py, it works like a charm. However, when using nginx and WSGI, the subprocess call fails with an exception that says: /bin/sh: 1: dotnet: not found.
I suspect this is due to the command not being accessible to the user and group running the server. I have used this guide as a reference to deploy the app, and on the wsgi .ini file, I have set uid = javierd and gid = www-data, while on the systemd .service file I have User=javierd, Group=www-data.
I have tried to add the executables' paths to /etc/profile, but it didn't work, and I don't know any other way to fix it. I find also very surprising that this happens to some executables, but not to all, and that it happes to dotnet, for example, which is located at /usr/bin/dotnet and therefore should be accessible to every user. Any idea on how to solve this problem? Furthermore, if somebody could explain me why this is happening, I would really appreciate the effort.
Thanks a lot!
Ok, finally after having a big headache, I noticed the error, and it was really simple.
On the tutorial I linked, when creating the system service file, the following line was included: Environment="PATH=/home/myuser/myfolder/enviroment/bin".
Of course, as this was overriding the path, there was no way of executing the commands. Once I notices it I just removed that line, restarted the service, and it was fixed.
I currently have a http server implemented in python using flask. The service is registered using the zeroconf module:
info = ServiceInfo('_http._tcp.local.',
'MyServer._http._tcp.local.',
inet_aton(host), port, properties={})
zc = Zeroconf()
zc.register_service(info, allow_name_change=True)
Also, I have a go application browsing the available services using zeroconf. The problem is that if I start the go program after the python server the go program never discovers the server. If I start the go program first there's no issue. I even try extending the ttl on the register_service function with no results.
I'm trying that the go program discovers the python servers that where already running when it gets started.
I recently discover that the go part functions perfectly, I register the service using avahi-publish and go discover it correctly. So I guess the python module is the problem. I know now that I can run avahi but I would like a python implementation of the protocol, having dependencies only in python.
I am trying to run simple pjsip application in daemon mode. I have combined this library with python twisted. Script works fine when I run it in shell & can make call. But when I use it with twisted's Application framework, I get following error.
Object: {Account <sip:192.168.0.200:5060>}, operation=make_call(), error=Unknown error from audio driver (PJMEDIA_EAUD_SYSERR)
Most of example applications from documents do not run in daemon mode - pjsip examples.
Looks like even pjsua doesn't run in background - pjsua
I am wondering, does it work in background. I am not getting exactly what "Unknown error" meant to. Is there any better way to debug ?
Architecture of my application is as follows -
Start pjsip lib, initiate pjsip lib, create transport & create userless account.
Create UDP protocol which listens for incoming requests.
Once app gets request, it makes calls to particular sip uri.
Everything goes well when I run app with listenUDP & reactor.run() but when I tries with typical twisted application setup - twistd( either listenUPD or UDPServer) above error pops up.
Am I doing anything wrong ? Any info will be welcomed.
thank you.
This issue resolved after I set sound devices.
In order to access a Reviewboard server I need to disable the SSL verification, however, I can't seem to do this from Reviewboard's Python API.
I've added a 'DISABLE_SSL_VERFICATION = True' line to ~/.reviewboardrc. The rbt commands themselves find this file ok, but scripts using the Python API don't seem to know it exists.
I'm seeing this behavior on both Ubuntu and a Cygwin install under Windows.
Is there something I'm missing with setting my Reviewboard configuration? Is there another way to disable SSL verification with the Python API?
I wasn't able to disable ssl verification globally, but there is a way to disable it when creating the RBClient that then carries through to any operations performed using that client.
Originally I was creating my client as below:
client = RBClient('server_url')
To disable ssl verification I added a verify_ssl argument and set it to false:
client = RBClient('server_url', verify_ssl=False)
Use the option —disable-ssl-verification for all rbt commands.
For example to post to Review board using retools use the command below.
rbt post —disable-ssl-verification
The exact reason why this is required is because of the Python Library. If you are using a Python Library version greater than 2.7.9 you will need this additional option.
I am writing a script in python, and part of it needs to connect to a remote computer using rdp. Is there a script or an api that I could use to create this function? Also, if there is not, is there a way to package a rdp application along side python and then use a python script to run it? Any help would be much appreciated. Thanks in advance, Nate
If you need an interactive window, use the subprocess module to start your rdesktop.exe (or whatever).
If you need to run some command automatically, you're probably better off forgetting about RDP and using ssh (with passwordless, passphraseless authentication via RSA or similar), psexec (note that some antivirus programs may dislike psexec, not because it's bad, but because it's infrequently been used by malware for bad purposes) or WinRM (this is what you use in PowerShell; it's like ssh or psexec, except it serializes objects on the sender, transmits, and deserializes back to an object on the recipient).
Given a choice among the 3, I'd choose ssh. Cygwin ssh works fine, but there are several other implementations available for Windows.
HTH
As per this GitHub comment, you can try to use libfreerdp via ctypes in Python.
See: FreeRDP library at GitHub which is a free remote desktop protocol library and clients.
Home page: www.freerdp.com
Related: Programmatically manipulating active RDP session.