I generate an .odt file in a flask app using something like :
return send_file( # imported from flask
BytesIO(data), # importe from stdlib
attachment_filename=filename,
as_attachment=True
)
On my machine with Ubuntu using either Firefox or Chromium, I download the file fine. It opens like a breathe.
On another machine, on the same wired network but using a corporate windows setup and still Firefox, the file is missing bytes. The file size varies from download to download without any clear pattern, and is about 100/200ko smaller.
I tried with curl on said machine, and got the same results with missing bytes.
The server is a python 3.6 flask 0.12 powered website on a debian with gunicorn + nginx.
I found the problem: the machines where it doesn't work are the ones with kaspersky installed. If you disable it, the bytes are here. Now I have to find a way to tell the AV I'm not evil. I opened another question about it.
Related
We have developed code to compile calculations into tex files and then convert to pdf's. We are now trying to instead of generating the pdf on local PC's to simply send the tex file to a hosting PC and prompting this PC to run a python file (using its own Python.exe instance) that will then generate the PDF and send to a server folder.
It might seem like a silly approach (since it can be generated on the local PC) but we are trying to remove the step where people have to install software like MikTex and Strawberry on local PC's completely and not use an online converter like Overleaf.
Is there a way that this is possible?
I'm working on a project for a client and his code is running on his server. I've tried to download the code so that I can run a local version on my computer. The project is at least 5 years old and runs on Python 2.7.
The problem is I can't run python install -r requirements.txt without running into errors, because some of the files are no longer available. Specifically something called "sorl", "django-page-cms", "mercurial", and a few files the developer hosted on other sites.
If his website is working & the code is functioning on his server, that means there is a working version of these packages stored on the server? How could I find them?
You can try starting python while sshed into the server and doing an import like:
>>> import sorl
>>> sorl.__file__
'/home/jmunsch/PycharmProjects/projectname/venv_ok/lib/python3.6/sorl/__init__.py'
And if the os is the same then rsync the files over.
see:
- Copying files using rsync from remote server to local machine
I am trying to figure out how to play an mp3 that exists on my server served through HTTP. I tried to figure out pyglet but there were too many issues with AVBin to make that work (something about dividing by zero in the source code). So, I decided to try PyAudio, but I can't figure out how to stream an mp3 source from HTTP with it. All the examples are wav files and I need examples rather than the docs or I'm afraid I'll have to figure out the particulars of how audio works on the lowest level. All the documentation is confusing for those of us that don't know the lingo (sample rate, etc). Can anyone help?
What is your source and target server environments? [ windows / linux / mac? ]. Also are your trying to play an audio file or video?
In either case you can use Gstreamer with python. I've windows laptop, so I tried with Gstreamer 1.0.x from here
Online examples are for Gstreamer 0.10 that does not work with newer Gstreamer 1.0. There lots of modifications that are platform specific.
However, on windows Gstreamer comes with gst-launch binary which works off the shelf. [ For Linux there is equivalent binary ]
Setup
Server Side:
On server side, you need to setup HTTP server. Without knowing specifics of your environment I can say that there are various solutions available , including python http server SimpleHTTPServer.
See solution here
Client Side :
Once http server is installed and running, on your laptop, you can simply run
C:\Python27\Lib\site-packages\gnome> .\gst-launch.exe playbin uri = http://www.freesound.org/data/previews/148/1482641337920-lq.mp3
Replace http server address with your server address and port.
You can call gst-launch in your python script and go creative with it.
OutPut:
I've opened audio files from freesound.org successfully. It should open a audio file being served from your http server as well.
Some of my Python shell scripts are newly throwing security errors under Apple OSX 10.11, El Capitan. It seems the new App Transport Security doesn't like how the scripts are calling HTTP resources in plain text, rather than using HTTPS.
Fetching http://blahblah.com
Python[5553:5648168] App Transport Security has blocked a cleartext HTTP (http://)
resource load since it is insecure. Temporary exceptions can be configured
via your app's Info.plist file.
How might I go about fixing this? There is no HTTPS resource I can call, so I'm stuck with HTTP. The advice from Apple is to make an exception in the app's info.plist file, but this is a Python script invoked from a shell script, so there is no info.plist file to be edited.
Ideas? The root problem seems to be with webkit2png, which is in Python. Its non-HTTPS requests are being blocked by ATS, and there is no info.plist to modify.
I found a solution here that worked for me: https://apple.stackexchange.com/questions/210588/how-does-one-configure-a-temporary-exception-to-ats-on-el-capitan-and-fix-webkit
First make sure you have a version of webkit2png that is new enough to have the --ignore-ssl-check option. Version 0.5 does NOT have this option.
Second, you need to edit the source file and add a couple lines of code as shown here: https://github.com/bendalton/webkit2png/commit/9a96ac8977c386a84edb674ca1518e90452cee88
Finally use option as indicated in the solution linked above (copied here for convenience):
webkit2png --ignore-ssl-check [options] [http://example/]
Thanks for Arthur Hebert
At first I'm confused for the code then I figure it out
so I summarise the steps as follows for reference
import AppKit
Add the following code in your py script
AppKit.NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] = dict(NSAllowsArbitraryLoads = True)
Assume you are sure to use no HTTPS resource in MAC OSX higher than 10.11
The installation of webkit2png is not necessary in my case
I'm working with a simple website (a few html files and one Python script) that's running on my LAN. In Chrome I can pull up the HTML files and Python scripts through port 80, as normal and I am using WSGIScriptAlias commands in /Library/Server/Web/Config/apache2/httpd_wsgi.conf that are working and I've set up the site and specified for it to be allowed to use Python apps through the Server GUI application.
For several reasons, I'm using a different port number for this site. If I go to http://mycomputer.lan:1234/myfile.html, I can see the HTML file. But if I go to http://mycomputer.lan:1234/MyWSGIApplicationScript, the server (the latest version, got it installed today) reports:
Not Found
The requested URL /LandSearch was not found on this server.
I've seen this work before, on other servers and I remember setting it up and getting it working on another system running OS X so the wsgi scripts worked fine on a non-standard port, but I don't have access to the notes and information I had at that time. That makes me suspect it's probably a simple configuration option I need to change for the server to find and use the Python scripts from a different port.
What do I need to reconfigure to get it to use wsgi scripts on a non-standard port?
Even AppleCare didn't have an answer for this one.
When I first set up the site, I enabled the 'Python "Hello World" app at /wsgi'. This is in the advanced settings:
I did that just for testing, so when I set up the site again, I didn't bother with it. It turns out that this one setting does more than enable one wsgi application. It turns out that, by default, the file /Library/Server/Web/Config/apache2/httpd_wsgi.conf is not read by Apache while setting up a virtual host. But checking the box to enable this one wsgi webapp means that the following line:
Include /Library/Server/Web/Config/apache2/httpd_wsgi.conf
will be included in the configuration file for this particular virtual host. Any scripts aliases defined with the WSGIScriptAlias command in that file will now be available to your website, no matter what port your website is on.