Q: How to write a python script to get a json for a speicific comic

Avatar image for moxxwell
Moxxwell

2

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

Hi! I'm very new to API, so please bear with me.

I have the following api reqest to get a comic info by id:

response = requests.get("https://comicvine.gamespot.com/api/issue/4000-14582/?api_key=YOUR-KEY&format=json")

... but only get a 403 as a response. However doing this inside a browser I get a nice json as a response.

Any idea why?

Avatar image for buzzinteractiv1
buzzinteractiv1

1

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

To write a Python script that fetches a JSON for a specific comic and allows you to write a comment, you can use the requests library to make API calls and the json module to handle JSON data. For this example, I'll assume you want to interact with a web API that provides comic data and comment functionality. https://www.buzzinteractive.co/

Here's a short Python script that demonstrates how to achieve this:

python
import requests def get_comic(comic_id): api_url = f"https://api.example.com/comics/{comic_id}" response = requests.get(api_url) if response.status_code == 200: comic_data = response.json() return comic_data else: print(f"Failed to get comic data. Status code: {response.status_code}") return None def post_comment(comic_id, comment): api_url = f"https://api.example.com/comments" comment_data = {"comic_id": comic_id, "comment": comment} response = requests.post(api_url, json=comment_data) if response.status_code == 201: print("Comment posted successfully!") else: print(f"Failed to post comment. Status code: {response.status_code}") def main(): comic_id = "123" # Replace with the specific comic ID you want to retrieve and comment on comment = "This comic is hilarious!" # Replace with your desired comment comic_data = get_comic(comic_id) if comic_data: print(f"Comic Title: {comic_data['title']}") print(f"Comic Description: {comic_data['description']}") post_comment(comic_id, comment) if __name__ == "__main__": main()

Remember to replace the placeholder URLs with the actual API endpoints provided by the comic service you're interacting with. Additionally, make sure you have the requests library installed in your Python environment. You can install it using pip:


pip install requests

Please note that this example assumes the API endpoints and data format for the comic service and comment functionality. Adjust the code accordingly based on the actual API documentation and requirements.

Avatar image for benmclean
BenMcLean

1

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#3  Edited By BenMcLean

@buzzinteractiv1: As a programmer, I feel like the future of my profession is very safe when LLMs are still giving answers like that.

The question here is how to actually use the comicvine API specifically and how to apply one's API key when attempts like the original poster's code seem to be rebuffed by the server. I'm in the same boat. Would appreciate some help from actual humans that isn't written by ChatGPT, not out of ideological opposition to LLMs but just because they in fact don't work as a practical matter.

Avatar image for flips
flips

7

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

@benmclean: the best way is to use a python wrapper to access the API versus writing all that code to do it your self. There are a few out there. I tried a couple and the I have found is Simyan: https://github.com/Metron-Project/Simyan

There is a lot of good documentation and it has caching built in.

Avatar image for flips
flips

7

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#5  Edited By flips

@benmclean: @moxxwell:

The original issue is that the OP didn't put in a USER agent... I do realize it has been a year.

Looks like the server software doesn't like me posting the code....

No Caption Provided