Last modified: 2011-02-02 18:32:23 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T28624, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 26624 - ERR_INVALID_REQ when trying upload a file with API
ERR_INVALID_REQ when trying upload a file with API
Status: RESOLVED INVALID
Product: Wikimedia
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
PC Windows Vista
: Normal major (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-01-07 14:38 UTC by Jan Luca
Modified: 2011-02-02 18:32 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
PHP-Script to show error message (1.79 KB, application/x-httpd-php)
2011-01-31 11:00 UTC, Jan Luca
Details

Description Jan Luca 2011-01-07 14:38:22 UTC
See this, too: http://lists.wikimedia.org/pipermail/wikitech-l/2011-January/050958.html

When I try to upload a file with the API, I get this error:

Request: [unknown method] [no URL], from <my IP> via
amssq35.esams.wikimedia.org (squid/2.7.STABLE7) to [unknown host]
([unknown])
Error: ERR_INVALID_REQ, errno [No Error] at Sun, 02 Jan 2011 09:43:01 GMT

The source code of the program, you can get at: http://svn.toolserver.org/svnroot/p_commonshelper2/truck/ . The request is in the method upload() in the upload_class.php.
Comment 1 Brion Vibber 2011-01-07 22:03:55 UTC
unknown method, no URL, and ERR_INVALID_REQ all make me suspect that there's a basic problem with your HTTP request itself: the squid proxy servers which are Wikimedia's first line of response are giving you a complete rejection, saying it can't understand what you're telling it even enough to send it to the actual web servers.


It looks like you're manually constructing an HTTP request from scratch by mashing strings together. Make absolutely sure that you're doing this correctly, for instance:

* are all the variables correct?
* are their values actually getting interpolated?
* do you have any issues with mixtures of \r\n and \n? (\r\n should be used at the line separator, I believe, but unless your code is changing it you'll have *either* \r\n or \n depending on your OS's file encoding...?

You might for instance try dumping the string and checking it manually before sending it out. If you get the same, try making your request simpler -- take out some of those parameters and see what you get. Confirm that you can make an HTTP request _at all_ with this code, then add parameters back until you see what's wrong.


However in general, I'd recommend that you go ahead and use some existing HTTP library that can handle constructing an HTTP request with multipart form submission data, such as CURL or the PEAR HTTP_Request2 module.
Comment 2 X! 2011-01-07 22:05:32 UTC
I am having this same problem, using the regular cURL class in PHP. The relevant code: http://code.google.com/p/mw-peachy/source/browse/trunk/Plugins/image.php?r=330#415
Comment 3 Brion Vibber 2011-01-07 22:08:59 UTC
(In reply to comment #2)
> I am having this same problem, using the regular cURL class in PHP. The
> relevant code:
> http://code.google.com/p/mw-peachy/source/browse/trunk/Plugins/image.php?r=330#415

Got an exact sequence of commands to reproduce the issue with your code?
Comment 4 X! 2011-01-07 22:10:42 UTC
Not exactly, it's kind of complex. It also happens about 1 in 100 times, so it's not easily reproducable. You can get an idea of what API params I'm using.
Comment 5 Brion Vibber 2011-01-07 22:18:12 UTC
It sounded like the original poster's problem is *every* time rather than 1% of hits, so this likely isn't the same issue.

1% of the time is more likely to involve occasional bad processing or bugs on the server end, especially if resubmitting the same request works. That'd be something that needs to be worked out with server admins.
Comment 6 Jan Luca 2011-01-08 15:21:00 UTC
I test the request with my local Apache server and there are no problems. I can read out the parameters ($_POST[...]). 

My problem is reproducable with other input parameters.
Comment 7 Jan Luca 2011-01-08 15:25:29 UTC
The line endings are \r\n, because the file is created in Windows and my text editor show no mixtures.
Comment 8 Mark A. Hershberger 2011-01-28 19:43:28 UTC
Closing this since a reproducible test case hasn't been provided.  If you want to re-open it, please provide a test case so that we can reproduce the problem.
Comment 9 Jan Luca 2011-01-31 11:00:04 UTC
Created attachment 8071 [details]
PHP-Script to show error message

Here is a test file for the problem which works with curl.
Comment 10 Mark A. Hershberger 2011-02-02 18:32:23 UTC
You are not using the curl library correctly.

If you pass $message to as the value for CURLOPT_POSTFIELDS instead of $query_data it will work.

curl cannot be expected to translate arbitrary PHP data structures into usable POST data.

I recommend you use a HTTP client library (there are a few mentioned in http://willnorris.com/2009/03/http-client-library-for-php or you can try MediaWiki's own Http class (found in HttpFunctions.php).

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links