How to fix the Damn Opensea 403 Error in Python

Arjun Sunil
2 min readJan 18, 2022
Photo by Taylor Vick on Unsplash

We got rate limited. In production. On the day of our sale.

So, I was working on an NFT project that uses the Opensea API for a few operations, and few hours into going live; our backend stopped working. The API just wasn’t getting a successful response from Opensea.

Opensea API reliability was one of our fears in the back of our mind considering the scale at which our application was going to run.

But given the timeframe in which we had to go live, we just couldn’t spend enough time working on alternatives.

Okay, enough backstory. On to the fix

HOW DO I FIX THE DAMN THING?

This is what my snippet of code looked like that was trying to make the API request.

import requests
url = "https://api.opensea.io/api/v1/assets"
headers = {"X-Api-Key": config.get('OPENSEA_API_KEY')}
params = {'owner' : wallet, 'offset': offset, 'limit': limit}
response = requests.get(url, params=params, headers=headers)
print(response)
if response.status_code == 200:
return response.json()

This is what worked for me at scale.

import requests
url = "https://api.opensea.io/api/v1/assets"

--

--

Arjun Sunil
Arjun Sunil

Written by Arjun Sunil

Tinkerer by instinct, MLOps Engineer by trade ✌🏾 I solve real-world problems using Tech, AI & 3D printing. Connect: connect@arjunsunil.com

No responses yet