Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8945835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:20:57+00:00 2026-06-15T12:20:57+00:00

In attempting to write a python script to access GCS using service-based authorization, I

  • 0

In attempting to write a python script to access GCS using service-based authorization, I have come up with the following. Note that ‘key’ is the contents of my p12 file.

I am attempting to just read the list of buckets on my account. I have successfully created one bucket using the web interface to GCS, and can see that with gsutil.

When I execute the code below I get a 403 error. At first I thought I was not authorized correctly, but I tried from this very useful web page (which uses web-based authorization), and it works correctly. https://developers.google.com/apis-explorer/#p/storage/v1beta1/storage.buckets.list?projectId=&_h=2&

When I look at the headers and query string and compare them to the keaders and query of the website-generated request I see that there is no authorization header, and that there is no key= tag in the query string. I suppose I thought that the credential authorization would have taken care of this for me.

What am I doing wrong?

code:

credentials = SignedJwtAssertionCredentials(
      'xxx-my-long-email-from-the-console@developer.gserviceaccount.com',
      key,
      scope='https://www.googleapis.com/auth/devstorage.full_control')
http = httplib2.Http()
http = credentials.authorize(http)

service = build("storage", "v1beta1", http=http)

# Build the request

request = service.buckets().list(projectId="159910083329")

# Diagnostic

pprint.pprint(request.headers)
pprint.pprint(request.to_json())

# Do it!

response = request.execute()

When I try to execute I get the 403.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:20:59+00:00Added an answer on June 15, 2026 at 12:20 pm

    I got this working, however, the code I used is not fundamentally different from the snippet you posted. Just in case you’d like to diff my version with yours, attached below is a complete copy of a Python program that worked for me. I initially got a 403, just like you, which was due to inheriting your project id :). After updating that value to use my project ID, I got a correct bucket listing. Two things to check:

    1. Make sure the project id you are using is correct and has the “Google Cloud Storage JSON API” enabled on the Google Developer Console “Services” tab (it’s a different service from the other Google Cloud Storage API).

    2. Make sure you are loading the service accounts private key exactly as it came from the developer’s console. I would recommend reading it into memory from the file you downloaded, as I’ve done here, rather than trying to copy it into a string literal in your code.


    #!/usr/bin/env python
    
    import pprint
    import oauth2client
    from oauth2client.client import SignedJwtAssertionCredentials
    import httplib2
    from apiclient.discovery import build
    
    f = open('key.p12', 'r')
    key = f.read()
    f.close()
    
    credentials = SignedJwtAssertionCredentials(
          'REDACTED',
          key,
          scope='https://www.googleapis.com/auth/devstorage.full_control')
    http = httplib2.Http()
    http = credentials.authorize(http)
    
    service = build("storage", "v1beta1", http=http)
    
    # Build the request
    
    request = service.buckets().list(projectId="REDACTED")
    
    # Diagnostic
    
    pprint.pprint(request.headers)
    pprint.pprint(request.to_json())
    
    # Do it!
    
    response = request.execute()
    pprint.pprint(response)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am curretnly attempting to write a script in python that allows me to
I have been attempting to write a VBA Script that can parse out other
I'm attempting to write a short mini-program in Python that plays around with force-based
So, here's the deal. I am attempting to write a quick python script that
I'm attempting to write a simple python script that will calculate the squareroot of
I'm attempting to write a small python script that processes through CSV data. I
I am attempting to write a python daemon that will launch at boot. The
I'm attempting to write a very basic script using javascript. What I want to
I have a python script that parses an XML file that contains part information
I am attempting to write some tests using webtest to test out my python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.