Eth2 : urllib.error.HTTPError: HTTP Error 400: Bad Request

Hi, wondering why am I getting urllib.error.HTTPError: HTTP Error 400: Bad Request for the following .

url = “https://eth2-beacon-pyrmont.infura.io/eth/v1/beacon/states/{head}/root
response = urllib.request.urlopen(url)

works for url = "https://eth2-beacon-pyrmont.infura.io/eth/v1/beacon/headers" without any error.

Should be just head instead of {head} . Not sure why the choice of bracket, {}, to indicate a variable !! Often <> is used for the same purpose. .

1 Like

Hi @whatdhack, and welcome to the Infura community! Glad you figured out the problem, and thanks for posting your solution for others who may run into this same issue!

The 400 (Bad Request) status code indicates that the server cannot or will not process the request because the received syntax is invalid, nonsensical, or exceeds some limitation on what the server is willing to process. It means that the request itself has somehow incorrect or corrupted and the server couldn’t understand it. The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method . Therefore, it prevents the website from being properly displayed. The main thing to understand is that the 400 Bad Request error is a client-side error.

The cause of a 400 error can be a wrongly written URL or a URL that contains unrecognizable characters. Another cause of the error might be an invalid or expired cookie. Also, if you try to upload a file that’s too large. If the server is programmed with a file size limit, then you might encounter a 400 error.