1

I am trying to fetch data on the Blur unreleased api https://core-api.prod.blur.io.

If you visit the following url https://core-api.prod.blur.io/v1/prices on your browser you should be able to get a successful response.

However, if you try to make this request via a non-browsing method it fails. Here is one attempt among many others:

import requests

url = "https://core-api.prod.blur.io/v1/prices"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
    "Accept-Language": "en-US,en;q=0.5",
    "Accept-Encoding": "gzip, deflate, br",
    "Connection": "keep-alive",
}
response = requests.get(url+endpoint, headers=headers)
print("Status:", response.status_code)
print("Content-type:", response.headers['content-type'])

if response.status_code == 200:
    print("Data:", response.json())
Status: 403
Content-type: text/html; charset=UTF-8

Any idea how to solve this?

(another related post: API call working in chrome but not postman)

Joseph
  • 209
  • 2
  • 11

1 Answers1

1

As Michael M. rightly mentioned, the API is hitting a Cloudflare server which denies serving your request. The other way around is using selenium as below.

import json
from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome()

driver.get(url="https://core-api.prod.blur.io/v1/prices")
soup = BeautifulSoup(driver.page_source, 'lxml')
print(json.loads(soup.text))

and you get your desired json response.

{'ethereum': {'usd': 1821.09}}

Hope, it's useful.

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
  • Any idea how to use this kind of bypass method with aiohttp or websockets (they also have wss)? – Joseph Mar 20 '23 at 10:02