Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always get "Bad request (400)" #335

Closed
tonebender opened this issue Apr 1, 2019 · 7 comments · Fixed by #339
Closed

Always get "Bad request (400)" #335

tonebender opened this issue Apr 1, 2019 · 7 comments · Fixed by #339
Milestone

Comments

@tonebender
Copy link

I just got started with Requests, using it with php5.6.

For some reason I get the response "Bad request" (400) on every GET and POST request I try.

I've tested this:
$response = Requests::get('https://github.com/timeline.json');

with a number of URLs and they do respond (I get a github page) but they all say "Bad request" (400).

Tried with POST as well, the example in the docs:
$url = 'https://api.github.com/some/endpoint';
$headers = array('Content-Type' => 'application/json');
$data = array('some' => 'data');
$response = Requests::post($url, $headers, json_encode($data));
var_dump($response->status_code);
But it also gives 400.

Sorry for the noob question, but where do I begin to find the cause for this?
Is it because I'm using php 5.6?

Thanks!

@tonebender tonebender changed the title Always get bad request (400) Always get "Bad request (400)" Apr 1, 2019
@soulseekah
Copy link
Contributor

Looks like the bad request is coming from GitHub itself.
Try to do the same with https://requestbin.fullcontact.com/

@tonebender
Copy link
Author

Thanks for the suggestion!
I tried it, and the request I make from php/Requests is so bad that it isn't even generating a report on requestbin.
I tried it with a simple curl command on the command line instead (on the same computer as the php/Requests application), and that worked fine, generating a report on the requestbin page.
But as I mentioned above I do get a response from the pages I try to request from php, so the request goes out at least.

@tonebender
Copy link
Author

Just to be clear – it's not about github, I get "bad request" as response which ever webpage I try to request – google, yahoo, example.com. I also tried sending a request to my own webserver where I can check the access log, and it says the same there. In fact, this is all it says:
214.135.42.103 - - [02/Apr/2019:08:10:15 +0200] "GET / HTTP/1,1" 400 0 "-" "-"

@Zegnat
Copy link
Contributor

Zegnat commented Apr 28, 2019

0.0.0.0 - - [02/Apr/2019:08:10:15 +0200] "GET / HTTP/1,1" 400 0 "-" "-"

Is that the exact copy-paste from your access logs? Having a comma instead of a period as the decimal separator in the HTTP version looks super suspect. If that is what is being send, it is pretty obvious servers are responding with Bad Requests.

Could you try checking that you are using curl and not fsockopen as the transport? I think there may be a bug in fsockopen that makes it locale dependent… (If you have a locale set that uses commas for rendering floating point numbers, those will be used in the HTTP line.)

@rmccue
Copy link
Collaborator

rmccue commented Sep 15, 2019

Sorry, I can't offer support on this repo.

@rmccue rmccue closed this as completed Sep 15, 2019
@soulseekah
Copy link
Contributor

Why was this closed? This is a valid bug. There's a good PR associated with it.

@rmccue rmccue reopened this Sep 16, 2019
@rmccue
Copy link
Collaborator

rmccue commented Sep 16, 2019

Apologies, was too quick with my closing of issues.

@jrfnl jrfnl added this to the 1.7.1 milestone Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants