Status parameter not working when using python blogger api client
See original GitHub issueI’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:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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.
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.