Reputation: 75
I've seeing 403 RANDOMLY (works some times and fails the other times) while trying to authorize with Google API Client to make Google Big Query calls.
To provide more context, I'm making several api calls together 5-10 per second so when I make the calls sequentially, I don't get the error. However when I make several calls per second, I get the error. I checked the BigQuery Rate Limit here: https://developers.google.com/bigquery/quota-policy and it says I can issue upto 20 concurrent queries. I'm pretty sure, I'm not at the rate limit.
I'll appreciate any pointers or suggestions to address this systematically. Thanks, Navneet
Here's the code:
def initialize
client = Google::APIClient.new
path_to_key_file = "/Users/abcyoo/crazy/crazy-google-client-key.p12" #dev
passphrase = "XXXXXXXX"
key = Google::APIClient::PKCS12.load_key(path_to_key_file, passphrase)
service_account = Google::APIClient::JWTAsserter.new(
'[email protected]',
'https://www.googleapis.com/auth/bigquery',
key)
client.authorization = service_account.authorize
client.authorization.fetch_access_token!
bq = client.discovered_api("bigquery", "v2")
return client,bq
end
Here's the error message I receive:
Signet::AuthorizationError (Authorization failed. Server message:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Google Accounts</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" /><link rel='stylesheet' type='text/css' href='https://ssl.gstatic.com/accounts/o/1893590695-error_page_css_ltr.css'>
403. That's an error.
signet (0.4.5) lib/signet/oauth_2/client.rb:875:in `fetch_access_token'
signet (0.4.5) lib/signet/oauth_2/client.rb:888:in `fetch_access_token!'
app/controllers/application_controller.rb:105:in `initialize'
Upvotes: 2
Views: 444
Reputation: 26617
Are you calling client.discoverty_api 5-10 times per second? If so, that may be what is rate limiting you. Can you call this once or once per thread and reuse the bigquery service?
Upvotes: 1