Posts: 1
Joined: Sun Aug 11, 2019 9:11 pm

Apache2 cgid error for file upload, all other cgi works

Sun Aug 11, 2019 9:45 pm

[edit]error log entry originally posted with single line, edited to include a 2nd line that's logged at the same time[/edit]

I have a fairly simple website that works fine on a pi 3b. I've migrated it to a pi 4b and have hit an issue that I can't get past. Apache seems to be blocking any file uploads. It may be Python, but it seems more like the error happens outside of the python interpreter. The reason I say this is that the script executes if I remove the file input element of the submitting page. Also, other python cgi scripts also work fine. So this is NOT a basic cgi permission/config issue.

I've reimaged the sd card. After still hitting the same issue, I resinstalled apache2. I've verified that permissions on all of the relevant folders (/var/www/*, /etc/apache2/*, /usr/bin/cgi-bin/*) are the same as on the pi 3b+. I also verified that the apache configuration files are identical.

Environment details:
- Raspberry Pi 4b
- Apache2
- Python 2.7

The web browser displays an error that the server didn't return any content. The apache error log has the following error:

Code: Select all

<timestamp> [cgid:error] [pid 4006:tid 2953815072] (32)Broken pipe: [client ::1:57254] AH02651: Error writing request body to script /usr/lib/cgi-bin/, referer: http://localhost/uploadPics.html
<timestamp> [cgid:error] [pid 4006:tid 2953815072] [client ::1:57254] End of script output before headers:, referer: http://localhost/uploadPics.html
I've enabled cgi error logging, but it's never engaged. This is why I say that it seems like apache, in the cgid module, is causing the failure.

In the interest of troubleshooting, I've removed as many details as possible. The python script below has all of the includes, but just sends back a simple reply. No attempt to process the file. It works when I use a form that does NOT have a file input element. It also works if I just hit the script directly from the browser. But if I include the <input type="file"> element, then it fails.

Here's the HTML used to do the submit:

Code: Select all

		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="something.css">
		<link rel="stylesheet" href="">
		<link rel="stylesheet" href="">
	<body style="max-width:600px">
		<header class="w3-container w3-top w3-bar w3-theme">
			<h1><a href="./" class="navlink">&#8676;</a>&nbsp;&nbsp;Something</h1>
		<div class="w3-container">
			<div class="w3-cell-row">
				<div class="w3-cell w3-container">
					<h3 class="w3-text-theme">Upload a Picture</h3>
					<form action="/cgi-bin/" method="post" enctype="multipart/form-data">
						<p><input name="imagefile" id="imagefile" type="file" accept="image/*" required></p>
						<p><input name="title" type="text" size="30" placeholder="title" /></p>
						<p><textarea name="caption" placeholder="caption and/or names" cols="38" rows="3"></textarea></p>
						<div id="divpreview">
									<td><img id="imgpreview" class="rotate0" width="200" /></td>
									<td vertical-align="top"><input type="submit" class="w3-button" value="Upload Picture" /></td>
		<footer class="w3-container w3-bottom w3-theme w3-margin-top">
	<script type="text/javascript" src="images.js"></script>
Here's the simplified python script:

Code: Select all

#!/usr/bin/env python

import sys
import os, cgi
import cgitb; cgitb.enable()
So again, if I just remove the input type="file" element, then it works.

Return to “Troubleshooting”