Topic: [Resolved] Bug with JSON GET requests ?

Posted under Site Bug Reports & Feature Requests

Hello there !

I hope this is the correct forum category and I'm not breaking any forum rule here.

I've been using and maintaining a personal fork of 'e621dl' (https://github.com/wwyaiykycnf/e621dl) for my use. It has become relatively obsolete and I tried making it compatible with the new version of this site. But I may have found a bug :

I have written the following (Python3) code to test a GET request for some tags (let USERNAME, API_KEY and TAG be passed to this code as argument) :

import requests

USERAGENT  = '{}/e621dl_mod'.format(USERNAME)
BASE_URL  = 'https://e621.net/posts.json?'
parameters = {'tags':TAG}
headers = {'User-Agent': USERAGENT, 'login':USERNAME, 'password_hash':API_KEY}
#print('Auth:{}'.format(Auth))

r = requests.get( BASE_URL, headers=headers, params=parameters )
if r.status_code!=200:
    print('Error code {}'.format(r.status_code))
    sys.exit(0)
posts = r.json()['posts']

When I use most tags, everything is good. But I was testing this code against a list of tags and when I used it with

TAG='oppai_loli'

I found out that every post entry has

.. 'url': None, ..

I tried to use the equivalent url on a browser

https://e621.net/posts.json?tags=oppai_loli

I found out that, when I'm logged in e621 the url field is filled correctly but is set to 'none' when not logged in.

I checked the available doc here and on Github for answers but I don't understand what's happening.

My question is : Did I miss something in my logging in implementation (in the GET request) or is it a bug ?

Updated

the login and api_key fields are parameters, not headers,
or if you want to put them in the headers, you'll need to use the Authorization: header instead.
also password_hash isn't the right name, it's api_key

stuntbuspdp said: I checked the available doc here and on Github for answers but I don't understand what's happening.

To clarify, the actual problem is that you are running into the global blacklist, which includes these tags by default:

gore
scat
watersports
young -rating:s
loli
shota

Tag oppai_loli implicates loli, and thus is blacklisted. Although, IIRC, the URL should be null, not none.

bipface said:
the login and api_key fields are parameters, not headers,
or if you want to put them in the headers, you'll need to use the Authorization: header instead.
also password_hash isn't the right name, it's api_key

I tried changing it :

parameters = {'tags':URL2, 'login':USERNAME, 'api_key':API_KEY}
headers = {'User-Agent': USERAGENT}

It seems to work now !

It's weird because I remember that I tried passing login+api_key in 'parameters' at some point but changed it because there were other issues but it seems it all worked out in the end.

Thanks a lot ! I'll try to run the tests on my list of test tags again and close the thread if it's resolved

bitwolfy said:
To clarify, the actual problem is that you are running into the global blacklist, which includes these tags by default:

gore
scat
watersports
young -rating:s
loli
shota

Tag oppai_loli implicates loli, and thus is blacklisted. Although, IIRC, the URL should be null, not none.

Thanks for the info !
I don't know if it's a Python thing to translate 'null' into 'None'

add auth=('username', 'apikey') to r = requests.get( BASE_URL, headers=headers, params=parameters ) so it looks like r = requests.get(BASE_URl, headers=headers, params=parameters, auth=(...))

kiranoot said:
add auth=('username', 'apikey') to r = requests.get( BASE_URL, headers=headers, params=parameters ) so it looks like r = requests.get(BASE_URl, headers=headers, params=parameters, auth=(...))

Thanks for the advice ! Do you mean like this ?

BASE_URL  = 'https://e621.net/posts.json?'
parameters = {'tags':TAG}
headers = {'User-Agent': USERAGENT}

r = requests.get( BASE_URL, headers=headers, params=parameters, auth=(USERNAME, API_KEY) )

After testing : Well it seems that both work (login+api_key either in parameters or auth)

Thank you all very much, sorry for the probably dumb mistakes I do when I code. Have a good day !

  • 1