Reputation: 1309
In Prestashop 1.7 I'm trying to interact with webservice using prestapyt.
from prestapyt import PrestaShopWebServiceDict
prestashop = PrestaShopWebServiceDict('http:\\hostname.ext\api', 'APIKEY')
ps = prestashop.search('addresses')
I get this error
prestapyt.prestapyt.PrestaShopAuthenticationError: 'Unauthorized'
To try to understand if is an error of the library, I've tryied to connect at the API via browser.
Connecting at http:\hostname.ext\api I get a login request.
Inserting in the username filed the APIKEY and leaving the password field blank as indicated here I get the Unauthorized error again.
The authetication works only setting the APIKEY as querystring
http:\\hostname.ext\api?&ws_key=APIKEY
But this method is not available in prestapyt that user session authetication.
There's some setting on Prestashop that I missed or a way to understand this problem?
Thank you
Upvotes: 0
Views: 2784
Reputation: 1309
Found the problem and solved the case in this way.
The problem is not releted to Prestashop or prestapyt but relative to the server configuration (Apache + PHP).
Considering that in my case I'm working in a managed cloud service, I don't have in depth information about that.
But the result of this configuration is that the Authorization header does not appear in the $_SERVER
variable. The same behavior reported here:
Why are $_SERVER[“PHP_AUTH_USER”] and $_SERVER[“PHP_AUTH_PW”] not set?
I solved adding this statement to the .htaccess file in my Prestashop installation:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
As suggested here.
I hope to help others Prestashop users that incur in the same problem.
Upvotes: 4