Laravel and Guzzle HTTP '406 Not Acceptable' - php

I'm having an issue with Laravel and Guzzle. When ever I try this line of code with my external website 'violapractice.com' I get an error:
$res = $client->request('GET','http://violapractice.com/articles.json.php');
Client error: `GET http://violapractice.com/articles.json.php` resulted in a `406 Not Acceptable` response: <html><head><title>Error 406 - Not Acceptable</title><head><body><h1>Error 406 - Not Acceptable</h1><p>Generally a 406 e (truncated...)
I've tried requesting a none php file and get the same error:
$res = $client->request('GET','http://violapractice.com/test.html');
The odd thing is, if I use any other URL, like https://stackoverflow.com the GET request goes through with no issue.
Also, I tired using postman on http://violapractice.com/articles.json.php and it worked fine.
I've never experienced anything like this before. Ideas anyone?

In the end, I ended up turning off ModSecurity in the violapractice.com cpanel. I felt that the risk in doing this was minimal because the website is only accessible through admin login and has many layers of security.

Related

Mediawiki, problems with Parsoids [duplicate]

A lot of people have the same error for many different reasons, so, after trying a composer update, I've tried to investigate it starting from the browser and reconstructing step by step what is happening. It's really hard for me and I would really appreciate help from a PHP Developer!
From Chrome Developer Tools I could find the Ajax request in the background and the called url on the server
By playing with the url I realized that changing the action name returned a different error code, which let me understand that the current call is just a generic API in the middle between the browser and whatever is "apierror-visualeditor-docserver-http"
The Ajax call
{mysite}
/ api.php
? action=visualeditor
& paction=parse
&page=Cosa_c%27%C3%A8_da_fare%3F
Example
https://www.tematichedigenere.com/api.php?action=visualeditor&paction=parse&page=Cosa_c%27%C3%A8_da_fare%3F
The response from the Ajax call
The serverside call to rest api
Then I can see from the Apache server's log that the api page contacts the following url (returning 500)
GET
//rest.php/
{mywebsiteurl}
/v3/page/html/
Cosa_c%27%C3%A8_da_fare%3F/27246
?redirect=false
&stash=true
example
"GET //rest.php/www.tematichedigenere.com/v3/page/html/Cosa_c%27%C3%A8_da_fare%3F/27246?redirect=false&stash=true HTTP/1.0" 500 5621 "-" "VisualEditor-MediaWiki/1.38.2"
Another example of log (returning 404)
{an IP} - -
[04/Dec/2022:14:16:12 +0000]
"POST
/rest.php/
{mywebsiteurl}/v3
/transform/html/to/wikitext
/Riflessioni_sulla_sessualizz._femm._collegate_-_bozza%2Fprova
HTTP/1.0"
404
467
"-"
"VisualEditor-MediaWiki/1.38.2 X-Middleton/1"
Maybe the initial double / is wrong?
Anyway if I call the uri directly from my browser https://tematichedigenere.com/rest.php/www.tematichedigenere.com/v3/page/html/Cosa_c%27%C3%A8_da_fare%3F/27246?redirect=false&stash=true
The server does a antirobot check but I'm not sure that was the problem.
I've realized that the 500 error code hides a more complex real error which is returned by accessing directly the url from the log.
As you say, the visualeditor API is mostly just a proxy to the Parsoid API. The double / is wrong (check your $wgVirtualRestConfig settings maybe), I don't think it actually matters though. The error sounds like you are using incompatible library versions - make sure MediaWiki core and the VisualEditor extension are for the same release, and that the parsoid Composer library is up to date.
Update from OP:
the issue was solved. I simply had to delete the folder /vendor/wikimedia/parsoid and copy it from the fresh install. I couldn't see there were disalignment because of a problem in the compare tool. I got a lot of help in the IRC channel (not in Phabricator and not in Mediawiki forums, it seems IRC is really helpful for MW products).

Getting 411 error bad request in Evernote

We have three environments, Dev, QA and Prod.
We have a stable PHP running that connects with evernote , get token and fetch content.
we updated our QA environment to PHP 7.0 and now when via evernote when we try to fetch Token it returns
Invalid auth\/bad request (got a 411, expected HTTP\/1.1 20X or a redirect)
Here is the code
$oauth = new \OAuth($this->consumerKey, $this->consumerSecret);
return $oauth->getRequestToken($this->getEndpoint('oauth'), $callbackUrl);
I have checked that consumerKey etc and everything is correct.
I am not sure what error could be here since 411 is normally when you need to send content length, but in Evernote API they dont mention anything like this
Is this due to PHP 7.0 ?
Any help will be appreciated
Thanks
Yes, you probably need to send the content length.
Does Evernote change the API validation for the Content-Length?
I see there is another workaround proposed on Github.

Symfony2 app.php receiving POST request as GET app_dev.php works fine

So I'm creating a route that requires posting. The route is as follows:
my_route:
path: /myroute/login
defaults: { _controller: "MyBundle:Default:login"}
methods: [POST]
So I use postman to hit app_dev.php/myroute/login and I get the correct response that I am looking for, currently the page just returns "hello world". Now when I change postman to just hit app.php/myroute/login I get an error saying:
The server returned a "405 Method Not Allowed".
I'm really confused as to why it says method not allowed so I tailed the prod.log file and got the following:
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: "No route found for "GET /myroute/login": Method Not Allowed (Allow: POST)"
I'm sending the requests in postman as POST requests but somehow symfony is only seeing them as GET requests. Again I can change the url to app_dev.php/myroute/login and hit send and it works. I thought it was a caching issue so I tried the following to clear the caches:
$ php app/console cache:clear --env=prod --no-debug
This still doesn't clear my problem so I even removed all the files from app/cache/prod as well. I can't find anyone having issues that are similar to this so I'm hoping someone can point me in the right direction. I also thought it might be
After some more digging I discovered what the issue was. So I thought that maybe it was postman that was sending the incorrect method so I googled around for that which lead to this
Postman sending POST as GET
which lead to a question about htaccess files:
Redirect POST htaccess
So first off I set postman to hit app.php/myroute/login and xdebug showed the request method as GET. I moved the .htaccess file and hit the same url and the request method showed up as POST. Instead of hitting that url I moved my .htaccess file back and pointed at just /myroute/login and everything lit up. This was an extremely annoying exercise so I hope that this will save someone else in the future looking for the same problem.
for me the case was my mistake, i.e. i was sending to http instead of https

ISSUU: Upload not working - Response Code: 999 Internal server error

I'm trying to upload files via the API (issuu.document.upload). It worked in the past. But on new files I receive always the following response error:
{"rsp":{"_content":{"error":{"code":"999","message":"a66125aeaff42e3a893a985fdc9b659587880484 - Internal server error"}},"stat":"fail"}}
The document also does not show up in "My Publications" (http://issuu.com/home/publications)
There is no API documentation about this error code...
Problem solved (the ISSUU developers fixed it). From the ISSUU support team: "... It seems like there was some problems with our API servers, ..."

Am i using the API V2 or V3 in this piece of code?

My live, staging and localhost had a page where it had a map and store finder.
6 months down the line this now does not work and havent touched the code. I have renewed my API key and still no luck. Now i know the API V2 is now not in use and im wondering if i am using the wrong code (confused myself). In my store finder i have this url:
$url = "http://maps.google.co.uk/maps/geo?q=".urlencode($this->input->post('postcode'))."&output=json&key=MYKEY";
Now reading this page ( https://developers.google.com/maps/documentation/geocoding/#JSON ) this has changed but i just cant seem to get a valid url working!
The error i get is: Message: file_get_contents(http://maps.google.co.uk/maps/geo?q=sr3+4as&output=json&key=MYKEY): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
And when i type the url string into google i get this message:
We're sorry...
... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.
If someone can guide me to if my url string is wrong above OR if this is another issue i would appreciate it.
Thanks!
According to the upgrade guide this endpoint URL:
http://maps.google.co.uk/maps/geo
Is using the v2 geocoding API.
Developers switching from v2 may be using a legacy hostname — either maps.google.com, or maps-api-ssl.google.com if
using SSL. You should migrate to the new hostname: maps.googleapis.com.
This URL based on the information in the update guide works for me:
http://maps.googleapis.com/maps/api/geocode/json?address=nebraska&sensor=false

Categories