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

Sometimes getting http 401 on requests #2356

Open
alexgran opened this issue Dec 21, 2022 · 3 comments
Open

Sometimes getting http 401 on requests #2356

alexgran opened this issue Dec 21, 2022 · 3 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release.

Comments

@alexgran
Copy link

We are using current v2.16.2. This works fine most of the time.
But sometimes we get a http 401 back like this:

Google\Http\REST::decodeHttpResponse()
#1 [internal function]: Google\Http\REST::doExecute()
#2 /var/www/html/magento2/vendor/google/apiclient/src/Task/Runner.php(187): call_user_func_array()
#3 /var/www/html/magento2/vendor/google/apiclient/src/Http/REST.php(66): Google\Task\Runner->run()
#4 /var/www/html/magento2/vendor/google/apiclient/src/Client.php(920): Google\Http\REST::execute()
#5 /var/www/html/magento2/vendor/google/apiclient/src/Service/Resource.php(238): Google\Client->execute()
#6 /var/www/html/magento2/vendor/google/apiclient-services/src/Sheets/Resource/SpreadsheetsValues.php(271): Google\Service\Resource->call()
#7 /var/www/html/magento2/vendor/bobbie/module-tender/Helper/GoogleApi.php(189): Google\Service\Sheets\Resource\SpreadsheetsValues->update()
#8 /var/www/html/magento2/vendor/bobbie/module-tender/Model/GoogleSheet.php(91): Bobbie\Tender\Helper\GoogleApi->setSpreadSheetValue()
#9 /var/www/html/magento2/vendor/bobbie/module-tender/Model/TenderSheet.php(488): Bobbie\Tender\Model\GoogleSheet->setValue()
[2022-11-29T14:44:41.634244+00:00] main.ERROR: {
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [
      {
        "message": "Invalid Credentials",
        "domain": "global",
        "reason": "authError",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED"
  }
}
 [] []

Just milliseconds before I had successfull requests, and we are checking token lifetime frequently using:

 if ($this->getClient()->isAccessTokenExpired()) {
            // Refresh the token if possible, else fetch a new one.
            if ($this->client->getRefreshToken()) {
                $this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
                $this->persistToken($this->client);
@bshaffer
Copy link
Contributor

Hello, thank you for reporting this issue. Do you know if retrying the API works, or does this break the application from then on out?

@alexgran
Copy link
Author

Hi,
we haven't implemented an immediate retry logic yet, however if the next bunch of calls to google go out, usually minutes later, they work flawlessly

@nicolas-gautron
Copy link

Hello,

Same issue after an upgrade from google/apiclient v2.12.6 to v2.13.0

Implying an upgrade of :

  • google/apiclient-services v0.266.0 to v0.280.0
  • google/auth v1.22.0 to v1.24.0

@yash30201 yash30201 added the priority: p2 Moderately-important priority. Fix may not be included in next release. label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release.
Projects
None yet
Development

No branches or pull requests

4 participants