0

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

Stefano Giraldi
  • 1,211
  • 2
  • 13
  • 22

1 Answers1

4

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.

Stefano Giraldi
  • 1,211
  • 2
  • 13
  • 22
  • 1
    Solved my problem. Thanks! – vosicz Sep 09 '17 at 23:56
  • I have added this line then working fine, but when I enable prestashop SEO friendly url this line getting deleted. And also whether ever prestashop regenerate htaccess file this line is not in htaccess, so same problem is there. – Vinoth Kumar May 14 '22 at 08:13