Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

basehttprequesthandler

Writing response body with BaseHTTPRequestHandler

August 1, 2023 by Tarik

In Python3 string is a different type than that in Python 2.x. Cast it into bytes using either self.wfile.write(bytes(“<html><head><title>Title goes here.</title></head>/html>”,”utf-8″)) or self.wfile.write(“<html><head><title>Title goes here.</title></head></html>”.encode(“utf-8”))

Categories python Tags basehttprequesthandler, python Leave a comment

How to extract HTTP message body in BaseHTTPRequestHandler.do_POST()?

March 10, 2023 by Tarik

You can access POST body in do_POST method like this: for python 2 content_len = int(self.headers.getheader(‘content-length’, 0)) for python 3 content_len = int(self.headers.get(‘Content-Length’)) and then read the data post_body = self.rfile.read(content_len)

Categories python Tags basehttprequesthandler, basehttpserver, http, post, python Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa