Python Forum
Fixing - MIME type ("text/x-python") that is not "text/event-stream"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fixing - MIME type ("text/x-python") that is not "text/event-stream"
#1
Dear Python Experts:

I am very new to web development, although I've been programming on some level for a few decades.
I started with the Python forum because I am sure that a Python dev has probably run into this.
Also, I know that this could very well be a simple HTML issue.

My setup is Ubuntu 16.x, Apache2, HTML / JS and Python on the Server.
I'm 'trying' to use an SSE / Python / HTML - JS combo for the streaming of data from an Apache server to the browser.

The Issue:
My chrome browser indicates the following:

EventSource's response has a MIME type ("text/x-python") that is not "text/event-stream".
Aborting the connection.


Below I provided:
  • Python script
  • index.html - JS / HTML
  • Apache Access Log (portion)
  • Apache Error Log (portion)
  • Some highlighting to (potentially) help narrow the focus.


Thank you for looking at this.


Python Script:
This script resides on the Apache server at /var/www/HTML/Int_SSE.py and uses -wxrwxrwxr for rights.
*The rights and location NEED to change; but, this issue is more important.

PyCharm Result Output - Works as expected.
linux CLI: 'python /var/www/HTML/Int_SSE.py' - Works as expected.


#!/usr/bin/env python
# -*- coding: UTF-8 -*-# enable debugging

import sys
import time

def SendData():

print("Content-Type: text/event-stream\n\n")

iCount = 0;

while (True):
    iCount = iCount + 1

    print('event: message\n' + 'data: {"EEPROM_RebootCount": ' + '"' + str(iCount) + '"' + '}\n\n')

    sys.stdout.flush()
    time.sleep(1)

SendData()
index.html - HTML / Java Script

var evtSource = new EventSource('Int_SSE.py');
console.log('Credentials: ' + evtSource.withCredentials);
console.log('Ready State: ' + evtSource.readyState);
console.log(' URL: ' + evtSource.url);

... various checks, etc...

evtSource.onerror = function() { console.log("EventSource failed."); evtSource.close(); };



Chrome Console
Credentials: false
Ready State: 0
http://192.168.1.50/Int_SSE.py
EventSource's response has a MIME type ("text/x-python")
that is not "text/event-stream". Aborting the connection.
EventSource failed.

The console messages from index.html / js are being displayed as expected.
192.168.50 is the Apache Server
These are the ONLY messages in the console.



Apache Logs
/var/log/apache2/access.log
192.168.1.51 - - [22/Sep/2017:07:11:14 -0500]
"GET / HTTP/1.1" 200 2876 "-"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
192.168.1.51 - - [22/Sep/2017:07:11:14 -0500]
"GET /Assets/CSS/default.css HTTP/1.1" 200 873 "http://192.168.1.50/"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"
192.168.1.51 - - [22/Sep/2017:07:11:14 -0500]
"GET /Int_SSE.py HTTP/1.1" 200 773 "http://192.168.1.50/"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"


*The following is a little longer. I cut out content that I thought was completely unnecessary. If you scroll toward the bottom, an underlined row seems to be where the interesting part begins.

/var/log/apache2/error.log
[Fri Sep 22 07:11:14 event.c(1585): connections: 0 (clogged: 0 write-completion: 0 keep-alive: 0 lingering: 0 suspended: 0)
[Fri Sep 22 07:11:14 connections: 0 (clogged: 0 write-completion: 0 keep-alive: 0 lingering: 0 suspended: 0)
[Fri Sep 22 07:11:14 Request received from client: GET / HTTP/1.1
[Fri Sep 22 07:11:14 Headers received from client:
[Fri Sep 22 07:11:14 Host: 192.168.1.50
[Fri Sep 22 07:11:14 Connection: keep-alive
[Fri Sep 22 07:11:14 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36
[Fri Sep 22 07:11:14 Upgrade-Insecure-Requests: 1
[Fri Sep 22 07:11:14 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[Fri Sep 22 07:11:14 Accept-Encoding: gzip, deflate
[Fri Sep 22 07:11:14 Accept-Language: en-US,en;q=0.8
[Fri Sep 22 07:11:14 AH01626: authorization result of Require all granted: granted
[Fri Sep 22 07:11:14 AH01626: authorization result of <RequireAny>: granted
[Fri Sep 22 07:11:14 request authorized without authentication by access_checker_ex hook: /
[Fri Sep 22 07:11:14 Content-Type 'text/html' ...
[Fri Sep 22 07:11:14 ... did not match 'application/xml'
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match
[Fri Sep 22 07:11:14 Content-Type 'text/html' ...
[Fri Sep 22 07:11:14 ... did not match 'application/rss+xml'
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match
[Fri Sep 22 07:11:14 Content-Type 'text/html' ...
[Fri Sep 22 07:11:14 ... did not match 'application/x-javascript'
[Fri Sep 22 07:11:14 ... did not match 'application/javascript'
[Fri Sep 22 07:11:14 ... did not match 'application/ecmascript'
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match
[Fri Sep 22 07:11:14 Content-Type 'text/html' ...
[Fri Sep 22 07:11:14 ... did not match 'text/css'
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match
[Fri Sep 22 07:11:14 Content-Type 'text/html' ...
[Fri Sep 22 07:11:14 ... matched 'text/html'
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' matched
[Fri Sep 22 07:11:14 AH01384: Zlib: Compressed 8982 to 2519 : URL /index.html
[Fri Sep 22 07:11:14 Response sent with status 200, headers:
[Fri Sep 22 07:11:14 Date: Fri, 22 Sep 2017 12:11:14 GMT
[Fri Sep 22 07:11:14 Server: Apache/2.4.18 (Ubuntu)
[Fri Sep 22 07:11:14 Last-Modified: Fri, 22 Sep 2017 00:38:09 GMT
[Fri Sep 22 07:11:14 ETag: \\"2316-559bc6c48fe40-gzip\\"
[Fri Sep 22 07:11:14 Accept-Ranges: bytes
[Fri Sep 22 07:11:14 Vary: Accept-Encoding
[Fri Sep 22 07:11:14 Content-Encoding: gzip
[Fri Sep 22 07:11:14 Content-Length: 2537
[Fri Sep 22 07:11:14 Keep-Alive: timeout=5, max=100
[Fri Sep 22 07:11:14 Connection: Keep-Alive
[Fri Sep 22 07:11:14 Content-Type: text/html
[Fri Sep 22 07:11:14 Request received from client: GET /Assets/CSS/default.css HTTP/1.1
[Fri Sep 22 07:11:14 Headers received from client:, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Host: 192.168.1.50, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Connection: keep-alive, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept: text/css,*/*;q=0.1, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Referer: http://192.168.1.50/, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept-Encoding: gzip, deflate, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept-Language: en-US,en;q=0.8, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 AH01626: authorization result of Require all granted: granted, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 request authorized without authentication by access_checker_ex hook: /Assets/CSS/default.css, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/css' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/xml', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/css' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/rss+xml', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/css' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/x-javascript', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/javascript', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/ecmascript', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/css' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... matched 'text/css', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' matched, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 AH01384: Zlib: Compressed 1199 to 520 : URL /Assets/CSS/default.css, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Response sent with status 200, headers:, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Date: Fri, 22 Sep 2017 12:11:14 GMT, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Server: Apache/2.4.18 (Ubuntu), referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Last-Modified: Fri, 15 Sep 2017 22:50:17 GMT, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ETag: \\"4af-559423779dc40-gzip\\", referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept-Ranges: bytes, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Vary: Accept-Encoding, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Encoding: gzip, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Length: 538, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Keep-Alive: timeout=5, max=99, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Connection: Keep-Alive, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type: text/css, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Request received from client: GET /Int_SSE.py HTTP/1.1
[Fri Sep 22 07:11:14 Headers received from client:, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Host: 192.168.1.50, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Connection: keep-alive, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept: text/event-stream, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Cache-Control: no-cache, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Referer: http://192.168.1.50/, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept-Encoding: gzip, deflate, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept-Language: en-US,en;q=0.8, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 AH01626: authorization result of Require all granted: granted, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 AH01626: authorization result of <RequireAny>: granted, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 request authorized without authentication by access_checker_ex hook: /Int_SSE.py, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/x-python' ..., referer: http://192.168.1.50/[/color]
[Fri Sep 22 07:11:14 ... did not match 'application/xml', referer: http://192.168.1.50/[/color]
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/x-python' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/rss+xml', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/x-python' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/x-javascript', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/javascript', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'application/ecmascript', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/x-python' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'text/css', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type 'text/x-python' ..., referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'text/html', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'text/plain', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ... did not match 'text/xml', referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type condition for 'deflate' did not match, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Response sent with status 200, headers:, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Date: Fri, 22 Sep 2017 12:11:14 GMT, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Server: Apache/2.4.18 (Ubuntu), referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Last-Modified: Fri, 22 Sep 2017 12:08:33 GMT, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 ETag: \\"1e5-559c611591240\\", referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Accept-Ranges: bytes, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Length: 485, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Keep-Alive: timeout=5, max=98, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Connection: Keep-Alive, referer: http://192.168.1.50/
[Fri Sep 22 07:11:14 Content-Type: text/x-python, referer: http://192.168.1.50/
[Fri Sep 22 07:11:15 connections: 0 (clogged: 0 write-completion: 0 keep-alive: 0 lingering: 0 suspended: 0)
Reply
#2
Why are trying to this without a framework,like eg Flask that is good for small scripts.
It will be a mess if try to run Python script,HTML and JS without help from a WSGI framework.
Do you know about WSGI , PEP 3333 standard,
and all that have been done to make it easier for Python to work with web?
Reply
#3
If you check the network tab of Chrome (or any program to view the actual content that's transferred, such as curl or fiddler), do you see what you expect, or is Apache serving the python script as if it's just a plaintext file, instead of running it?
Reply
#4
Hi nilamo:

Completely missed that. Apache is sending back the python script as a plaintext file. So, Apache is not running it. Back to Apache...

Thank you. We can close this issue.
Reply
#5
That was just my first guess, since Apache (and most other servers) don't run executable files by default, except for php.  So you'd need to enable it in the config, or through a module that needs to be loaded.

Flask is a framework for python that makes a lot of web development easier (it was recommended earlier in the thread).  The docs, in particular, are really nice.  Here's their page on configuring Apache: http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/
Almost none of that config is specific to Flask, so feel free to copy it at will :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access text files, hidden behind 'm3u8' resources Pavel_47 4 2,237 Feb-19-2023, 02:47 PM
Last Post: Pavel_47
  Flask, read H5 text value tantony 4 1,440 Oct-31-2022, 05:29 PM
Last Post: tantony
  [Solved] Browser won't parse text from yaml loaded into Jinja SpongeB0B 1 983 Jul-07-2022, 09:37 PM
Last Post: SpongeB0B
  Python BeautifulSoup gives unusable text? dggo666 0 1,429 Oct-29-2021, 05:12 AM
Last Post: dggo666
  selenium wait for text question Larz60+ 3 2,544 Oct-25-2021, 09:50 AM
Last Post: Larz60+
  BeautifulSoup returning text as N/A tantony 6 2,729 Sep-09-2021, 12:59 PM
Last Post: tantony
  Extract Href URL and Text From List knight2000 2 8,965 Jul-08-2021, 12:53 PM
Last Post: knight2000
  How to get specific TD text via Selenium? euras 3 8,783 May-14-2021, 05:12 PM
Last Post: snippsat
  Python 3.9 : BeautifulSoup: 'NoneType' object has no attribute 'text' fudgemasterultra 1 8,909 Mar-03-2021, 09:40 AM
Last Post: Larz60+
  Scraping all website text using Python MKMKMKMK 1 2,082 Nov-26-2020, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020