Hello, when I get json from API there is no URL, even with authentication. The URL is there if I make the query with my browser. How can I make proper authentication with the API key with requests? There is no guide on help page, no posts in forum.
Posted under General
Hello, when I get json from API there is no URL, even with authentication. The URL is there if I make the query with my browser. How can I make proper authentication with the API key with requests? There is no guide on help page, no posts in forum.
dobrivoc said:
Hello, when I get json from API there is no URL, even with authentication. The URL is there if I make the query with my browser. How can I make proper authentication with the API key with requests? There is no guide on help page, no posts in forum.
Can you provide an example of the post you are trying to fetch?
Or is this the case for all results?
dobrivoc said:
Hello, when I get json from API there is no URL, even with authentication. The URL is there if I make the query with my browser. How can I make proper authentication with the API key with requests? There is no guide on help page, no posts in forum.
I presume you're trying to get the URL of an image that's in the default blacklist, which I think would need authentication.
For authentication you need to use HTTP Basic Auth, whatever language/library you're using likely has a way to do it.
With Python you can do:
import requests from requests.auth import HTTPBasicAuth session = requests.Session() session.auth = HTTPBasicAuth("E6 username", "E6 API key") session.headers = {"User-Agent": "Program_Name/1.0 (by Username on E621)"} response = session.get(URL) json = response.json()
E621 hides young content by default, so that's why it doesn't show that. You need to log in/authenticate to view it.
I do it like:
string AuthString = $"{UserName}:{API_Key}"; e621Request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(AuthString)));
bitwolfy said:
Can you provide an example of the post you are trying to fetch?
Or is this the case for all results?
In fact, this happened for all the posts I was trying to get, maybe I make mistake in the code. But now with the code from Pup it works, thank you.