question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Status parameter not working when using python blogger api client

See original GitHub issue

I’m trying to use google-api-python-client 1.12.5 with Service account auth under Python 3.8. It seems to me that the when specifying the status parameter, Google responds with a 404 HTTP code. I can’t figure out why. I also looked in the docs but I can’t relate anything to this error.

I have pasted my code. The error is happening in the third call.

This is the code:

from google.oauth2 import service_account
from googleapiclient.discovery import build

SCOPES = ['https://www.googleapis.com/auth/blogger']
SERVICE_ACCOUNT_FILE = 'new_service_account.json'
BLOG_ID = '<your_blog_id>'

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

service = build('blogger', 'v3', credentials=credentials)
p = service.posts()

# FIRST
promise = p.list(blogId=BLOG_ID)
result = promise.execute()

# SECOND
promise = p.list(blogId=BLOG_ID, orderBy='UPDATED')
result = promise.execute()


#THIRD
promise = p.list(blogId=BLOG_ID, orderBy='UPDATED', status='DRAFT')
result = promise.execute()  # <===== ERROR HAPPENS HERE!!!!

service.close()

And this is the traceback:

Traceback (most recent call last):
  File "/home/madtyn/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7660.27/plugins/python/helpers/pydev/pydevd.py", line 1448, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/madtyn/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/202.7660.27/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/madtyn/PycharmProjects/blogger/main.py", line 24, in <module>
    result = promise.execute()
  File "/home/madtyn/venvs/blogger/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/madtyn/venvs/blogger/lib/python3.8/site-packages/googleapiclient/http.py", line 915, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://blogger.googleapis.com/v3/blogs/<blog_id>/posts?orderBy=UPDATED&status=DRAFT&alt=json returned "Not Found">
python-BaseException

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
partheacommented, Nov 10, 2020

Hi @madtyn ,

I was able to re-produce the problem using your code. Initially, I used the code below which authenticates using oauth2 flow and the code didn’t raise an exception. My initial thought is that possibly the Blogger API does not support authenticating with a service account. On an unrelated note for the YouTube API, I have read that Service Accounts do not work with the YouTube API. If this is also the case with the Blogger API, then at the very least the error message that is returned should be improved. I have read from public unofficial sources that the Blogger API does not support service accounts, so you could also try opening a feature request on the issue tracker if you are unable to find an adequate solution: https://issuetracker.google.com

Working code with oauth flow:

from googleapiclient.discovery import build

SCOPES = ['https://www.googleapis.com/auth/blogger']
client_secrets_file = 'client_secrets_file.json'
BLOG_ID = '<your_blog_id>'

flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
    client_secrets_file, SCOPES)
credentials = flow.run_console()

service = build('blogger', 'v3', credentials=credentials)
p = service.posts()

# FIRST
promise = p.list(blogId=BLOG_ID)
result = promise.execute()

# SECOND
promise = p.list(blogId=BLOG_ID, orderBy='UPDATED')
result = promise.execute()


#THIRD
promise = p.list(blogId=BLOG_ID, orderBy='UPDATED', status='DRAFT')
result = promise.execute()  # No error using oauth2 flow

service.close()

I’ll keep this issue open while do a bit of digging internally to try to obtain more information about using service accounts with the Blogger API. I’ll also create an internal ticket to improve the error message.

0reactions
partheacommented, Nov 17, 2020

I wasn’t able to get confirmation that delegating domain wide authority to a service account is applicable to Blogger API but I was able to get confirmation internally that you cannot use a service account to get details of a blog. My initial thought is it likely won’t work as a service account cannot be added as an admin or author of a blog. Your best option would be to open an issue at https://issuetracker.google.com . You can read more about the issue tracker in general here. I still have an internal ticket open, so if you have specific questions about the Blogger API I’m happy to help attempt to find answers but generally issues and feature requests should go in https://issuetracker.google.com so they can be prioritized.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Status parameter not working when using python blogger api
I'm trying to use google-api-python-client 1.12.5 with Service account auth under Python 3.8. It seems to me that the when specifying the status...
Read more >
Blogger API: Using the API - Google Developers
Requests to the Blogger APIs for non-public user data must be authorized by an authenticated user. This process is facilitated with an OAuth...
Read more >
Python and REST APIs: Interacting With Web Services
HTTP status codes come in handy when working with REST APIs as you'll often need to perform different logic based on the results...
Read more >
How to Use the Python Requests Module With REST APIs
4xx Client Error – Indicates problems with the client, such as a lack of authorization, forbidden access, disallowed methods, or attempts to ...
Read more >
Python API Tutorial: Getting Started with APIs - Dataquest
API requests work in exactly the same way – you make a request to an API server for data, and it responds to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found