128 questions
0
votes
1
answer
164
views
Handling socket errors in Python HTTPServer when a client closes SSE gracefully
My code is using SSE technique (Server-Sent Events) to send Jpeg images every time a camera-viewer object is updated with a new frame. I'm using Python 3.9.13.
Inside `do_GET I have this code:
self....
1
vote
0
answers
399
views
BaseHTTPRequestHandler: how to return JSON from post request
I'm new in API creation and cannot create correct server code to return JSON data from POST request. I have a Python class that inherits BaseHTTPRequestHandler and implements the method do_POST.
...
0
votes
1
answer
80
views
HTTPServer: can't listen on Wifi when wire is connected (Windows)
I've encountered an unusual behavior with Python's HTTPServer. My computer has both Ethernet and WiFi connections active simultaneously. I intended for the server to exclusively respond to incoming ...
0
votes
0
answers
668
views
Setting up a publicly available Python HTTP server when SSH'd into another server
I am currently experiencing a strange issue when attempting to set up a publicly available internet server. I am seeking some insight into where I may be going wrong. I am pretty new to this sort of ...
0
votes
1
answer
360
views
Is there a way to start a new command prompt window from a get request in python HTTP server that doesn't interrupt the main thread?
This is my first time posting and I'm running into quite the issue. Unlike most people who want their code to execute a command and wait for it to finish, I want to launch it in a new terminal window ...
1
vote
1
answer
606
views
Pytorch Custom data loading with HTTPS is very slow
I tried implementing a custom data loader that will make a web request and will return a sample. My purpose of the program is to see if this idea would be faster than the original data loader. My web ...
3
votes
0
answers
1k
views
System Idle Process occupying a specific port
I'd like to ask about System Idle Process where it seems to be occupying a specific port that I'm using.
I'm suspecting this is the reason why my BaseHTTPServer python script that listens to requests ...
1
vote
1
answer
2k
views
How can I use BaseHTTPRequestHandler to forward(routing) the client's Get request to a local server file like Apache?
Let's say there is a path "D:/test.zip", and I have successfully built a server based on BaseHTTPServer( the server is listening on http://127.0.0.1:6000). Its handler class is like this:
...
1
vote
0
answers
1k
views
Run 2 Python3 `http.server` on the same machine, different ports
Situation: Need 2 ad-hoc Python3 http.server instances on the same computer.
Problem: The first server was started successfully on the command line
python3 -m http.server 8888
The second server was ...
0
votes
1
answer
820
views
Decode image from HTTP POST request in python
I am sending an image from my HTML-JS frontend to my Python backend. Below is my JS code:
var formData = new FormData();
formData.append("a", file);
var xhr = new XMLHttpRequest();
xhr....
0
votes
1
answer
682
views
Run Script on Get and Return response immediately
Apologies but I am super unfamiliar with Python httpserver. I am also aware of the vulnerabilities or limitations of it, but it is ideal for my needs.
I have about 10 lines of code that are running ...
0
votes
2
answers
873
views
Cannot instantiate python BaseHTTPServer on https port (443) [Errno 10013]
BaseHTTPServer cannot be instantiated with port 443. I guess this is prevented to avoid collision with some other https services.
Therefore, I've tried to define SNI to this server using the ...
0
votes
0
answers
110
views
PYTHON BaseHTTPServer and UWSGI
Please tell me in what form should I give the status of the server and the body of response from my application in uwsgi for proper work ?
import BaseHTTPServer
import AppLogic
class ...
0
votes
0
answers
2k
views
Allow CORS header causes ERR_INVALID_HTTP_RESPONSE
I'm trying to send a POST request to localhost and was getting an error about CORS not being allowed. I added an "Access-Control-Allow-Origin: *" header among other things based on what other people ...
3
votes
1
answer
3k
views
How can I set a timeout in Python HTTPServer
I have a Python (2.7.13) HTTP Server running in Debian, I want to stop any GET request that takes longer than 10 seconds, but can't find a solution anywhere.
I already tried all the snippets posted ...
1
vote
0
answers
84
views
HTTPS connection Python still loading the content until it's KeyboardInterrupted
Can anyone tell me what's the solution for this?
When I run it and load it from the browser... It's only loading and never displaying the "Hello Word!" text.
But the text will appear in the browser ...
0
votes
0
answers
213
views
Why the Python BaseHttpServer server stops after execution?
I am trying to develop application which will have a Python Webserver. Everything works as expected, but after executing the logic(by using do_GET and do_POST methods) the server just stops and a ...
1
vote
1
answer
1k
views
BaseHTTPRequestHandler : Multipart request parsing and Content-length issues
I'm having difficulties when parsing a raw HTTP request string and trying to confirm the calculated content-length value.
The issue was found when parsing a POST request containing multipart data. In ...
0
votes
0
answers
1k
views
Can a tkinter application use httpServer?
I currently have the below code which can be used as a demo. The code is set up to create a Tkinter window with a button. When the button is pushed it starts a HttpServer on the localhost. The issue ...
0
votes
1
answer
161
views
How to print an empty date_time_string in BaseHTTPRequestHandler?
I have built a tiny httpd using BaseHTTPRequestHandler in Python3. At the moment, it logs every HTTP GET request in systemd journal like this:
Oct 18 23:41:51 ubuntu httpd.py[19414]: 192.168.0.17 - - ...
0
votes
1
answer
466
views
Python : http.server.HTTPServer : How to close ALL opened files?
So basically, I am making an HTTP webhooks server in Python 3 and wanted to add a restart function because shell access is very limited on the server it will be running on.
I found this snippet ...
0
votes
1
answer
129
views
PI Camera not working with disconnected display
I'm running an HTTP server written in python on my rasberry pi. The server takes images using a pi v2 camera module.
I have set crontab to auto start my script 30 seconds past boot.
The system ...
1
vote
0
answers
86
views
KeyError in Python BaseHTTPHandler while parsing HTTP GET request
def do_GET(self):
logging.info("GET request,\nPath: %s\nHeaders:\n%s\n", str(self.path), str(self.headers))
self._set_response()
params = parse_qs(urlparse(self.path).query)
...
1
vote
2
answers
1k
views
Unable to run BaseHTTPServer in Docker
I have the following python code, where I have written a simple HTTP server by extending HTTPBaseServer:
class ApiError(Exception):
def __init__(self, code, msg=None, desc=None):
self....
-1
votes
2
answers
328
views
Object is not iterable when replacing word called by function
How do I get otherImages to return the string in it so that I can replace a word within it when called from 'narrow' method?
def otherImages(self):
self.wfile.write(bytes("<div id='...
-1
votes
1
answer
52
views
How to change a string in a function when calling a function after it passes through list?
Is there way to change the word cat to dog in string() when calling it in main()?
For example:
def notimportant2("Not using this."
def notimportant1("Not worried about this.")
def string():
...
0
votes
1
answer
1k
views
How to pass Queue to baseHTTPServer
I'm using the example bellow with Thread, a simple http server to listen to post request and collect the data for the main process.
I want to convert it to use multiprocessing and passing a Queue in ...
2
votes
1
answer
4k
views
How to access RequestHandlerClass for HTTPServer in Python once it is set?
I have a custom BaseHTTPServer.BaseHTTPRequestHandler that can (partially) be seen below. It has a special method that allows me to assign a reply generator - a class that takes some data in (for ...
0
votes
1
answer
292
views
Python BaseHTTPServer, how to redirect multiple hosts to ip/port?
I currently have the following code:
from BaseHTTPServer import BaseHTTPRequestHandler
from pathlib import Path
from random import randint
import json
import random
example = 'logs/example.json'
...
0
votes
0
answers
99
views
Scalability of python's BaseHTTPHandler?
I am using python's standard API (BaseHTTPServer.BaseHTTPRequestHander) as a backend for handling users' HTTP requests. Now, assuming on an average, the number of users on my website will be around ...
0
votes
1
answer
1k
views
a web server developed by python, how to transfer a image file, and can show in a web browser?
I want to develop a simple web server using python to handle some simple http request. I have learn how to response the request, such as transferring html pages or transferring some other file. When I ...
0
votes
1
answer
3k
views
python3 HTTPServer/BaseHTTPRequestHandler output stream issue
I have faced an issue with a built-in python3 http.server module. Specifically, wfile.write() method in BaseHTTPRequestHandler class.
I'm trying to send an html form pre-defined as a string to a ...
14
votes
1
answer
26k
views
Serve a file from Python's http.server - correct response with a file
I am simply trying to serve a PDF file from the http.server. Here is my code:
from http.server import BaseHTTPRequestHandler, HTTPServer
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):...
2
votes
0
answers
544
views
Requests to python API stalled by chrome for 10 seconds for no reason. [BaseHTTPServer + Chrome]
Overview of the problem
I am running a webpage and an API written in python. The webpage sends some data to the python API in a POST request, which processes it and sends it back. The API works fine ...
0
votes
1
answer
2k
views
Dual HTTP and HTTPS Python server based on BaseHTTPServer not working as expected
I'm trying to implement a Python server supporting both HTTP and HTTPS based in BaseHTTPServer. This is my code:
server_class = BaseHTTPServer.HTTPServer
# Configure servers
httpd = server_class(("0....
2
votes
2
answers
2k
views
Python 3's http.server.HTTPServer has a one second delay on localhost
I've got a client and a server running on the same box. The client is able to issue urllib.request.Request() commands to external URLs and get responses back in about 0.1 seconds, fast enough that as ...
0
votes
2
answers
1k
views
Empty POST request from HTML form (Python)
I am trying to receive POST requests in Python using the BaseHTTPRequestHandler module. I wrote a simple HTML form:
<html>
<head>
<meta charset='UTF-8'>
</...
0
votes
1
answer
538
views
Writing an HTTP serrver with context in python
I'm trying to write an HTTP server in python 2.7. I'm trying to use ready-made classes to simplify the job (such as SimpleHTTPServer, BaseHTTPRequestHandler, etc.).
The server should listen for GET ...
0
votes
1
answer
1k
views
BaseHTTPServer POST request - Connection Reset
I am building a simple Python tool that takes GPS coordinates from an external receiver via COM port and translates it to a JSON string like is returned by Google Geolocation API. The purpose is to ...
1
vote
0
answers
3k
views
Python BaseHTTPServer CGIHTTPServer
I am trying to implement a simple HTTP server with a form enabling the user to upload a file.
I have got three code files:
- A python script creating the webserver with BaseHTTPServer and ...
2
votes
3
answers
13k
views
Remove cache in a python HTTP server
I found this server online and I edited it a bit.
Here is the code:
from http.server import BaseHTTPRequestHandler, HTTPServer
from xml.dom import minidom
import os
class MyHandler(...
0
votes
1
answer
2k
views
How to get HTTPServer to pass my own class back with do_GET's?
I have a special database class instance that i want passed into an HTTPServer handler so that I can have it returned for use in my do_GET and do_POST callback handlers. I tried subclassing to add my ...
1
vote
0
answers
841
views
SSL session cache fails in python 2.7
I'm trying to set up an HTTPS server using python, and SSL session caching doesn't work. Here's a minimal reproduction. The certificate is a simple self-signed certificate and key that I produced with ...
-1
votes
1
answer
938
views
Python's BaseHTTPServer returns junky responses
I use Python's BaseHTTPServer and implement the following very simple BaseHTTPRequestHandler:
class WorkerHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.wfile.write('{"status" : ...
11
votes
3
answers
31k
views
Python BaseHTTPRequestHandler: Respond with JSON
I have a Python class that inherits BaseHTTPRequestHandler and implements the method do_POST.
I currently only succeed to respond with an integer status, e.g. 200, using the following command at the ...
2
votes
0
answers
407
views
javascript protocol buffer decode data from python server failed
I am using javascript as client and a python as server.
I need to send/receive in between them using protocol buffer.
My proto looks like this :
message CMsgBase
{
required CMsgHead msghead ...
4
votes
3
answers
6k
views
Pass Parameter to SimpleHTTPRequestHandler
I have to pass a parameter to SimpleHTTPRequestHandler class, so I used class factory to create a custom handler as below.
def RequestHandlerClass(application_path):
class CustomHandler(...
0
votes
1
answer
503
views
Add custom request mapping in python-telegram-bot embedded HTTPServer.HTTPServer
i have just rewritten my telegram bot from pyTelegramBotAPI with python-telegram-bot. There was an idea to have a monitoring url available publicly that we could ping once in a while with some app to ...
5
votes
0
answers
1k
views
javascript client to Python server: XMLHttpRequest responseText is empty after Get request
I am trying to write a chrome extension which is able to send/receive data to/from a python server script. Currently, I am at the point where the js script is making a GET request okay, the only issue ...
3
votes
1
answer
1k
views
Why is do_GET much faster than do_POST
Python's BaseHTTPRequestHandler has an issue with forms sent through post!
I have seen other people asking the same question (Why GET method is faster than POST?), but the time difference in my case ...