When I call the balanceOf function for a contract and specify a block number in call(), I receive a forbidden URL error - web3py

When I use contract.functions.balanceOf(wallet_address).call(block_identifier=block_num) I get a forbidden URL error, but if I run the same call without using the block_identifier argument, it works as expected. What is the reason that this is happening?

Related

Getting KeyError of missing `code` argument

I use authlib with MSAD and I am getting KeyError on line:
https://github.com/lepture/authlib/blob/master/authlib/integrations/flask_client/integration.py#L43
My question is if there has to be always code argument within request or IMHO this is bug and it should be checked by get() method same as state.
I use it with flask and after proper registration of MSAD client I try method authorize_access_token() and from here I get to the poit of code I mentioned above and get error.
Thanks for any advice.
Vit
Are you using debug mode of Flask? In production, this code will raise 400 Bad request error.

Flask Error: If something fails in the flask backend, how does the error propagate to the front end?

Consider a simple application where a user fills a form to divide two numbers, in the routes the form data is proceeded [made into float] and then passed as parameters to a python script's function that has the division logic.
The logic fails due to division by 0 is handled as a custom message in the terminal. How does one send this custom message back to the front end UI along with a 500 error message? Trying to make a restful flask app here.
So far I can abort and show a custom message but not the one that propagated from the backend. Also looked into custom error handling but I want to writer of the external python script to be able to write the custom message.
You can Flask errorhandler(errorcode) to manage your errors and display those on the frontend.
#app.errorhandler(500)
def code_500(error):
return render_template("errors/500.html", error=error), 500
You can put whatever else you want in the html template.
You can also call the code_500(error) func directly.
Same principle applies for any other HTTP error code if you want to customize the page and the message (401, 403, 404, etc...).
If you're inside a blueprint, you can use app_errorhandler instead.
You could use the abort() function. From the docs:
When using Flask for web APIs, you can use the same techniques as above to return JSON responses to API errors. abort() is called with a description parameter. The errorhandler() will use that as the JSON error message, and set the status code to 404.
You could implement it like this
#app.route("/div")
def divide():
x, y = request.form['x'], request.form['y']
try:
result = x / y
except ZeroDivisionError:
abort(400, description="Your message here")
else:
# Proper response
From there, the important step is properly catching that message on your frontend.

Post method gets converted to GET after redirection

I have one POST call related to search.It is like I am sending some data as parameters to call and some in payload.after getting 302 it gets redirected.But the issue is once it gets redirected,POST call gets converted to GET call and payload is lost.As a result I am unable to get desired search result.Is there anything related to config that I might be missing??
Yes this is the correct behavior. Sounds like you need to disable automatic re-directs for this test, see configure. You can do:
* configure followRedirects = false
And then get the redirect location manually as follows:
* def location = responseHeaders['Location'][0]
Refer to this test for an example: redirect.feature

Nest1.0: ConnectionStatus error handling

I have a question regarding to Nest1.0pr and the connection error handling. In the previous versions of Nest I was using IResponse.ConnectionStatus.Error. It seems to me that the property Error does not exist in the new version anymore. However in the documentation I found the following:
ConnectionStatus is the response as it was returned by
Elasticsearch.net. It's section on handling responses applies here as
well.
And in the very section the property Error is mentioned.
Error When a call succeeds but does not return a http status code of
200 this property will have details on the error. Read more about
error handling here
So is the recommended way to check whether the property Success is false?
TIA
This changed when NEST was refactored to use Elasticsearch.Net. Now when a request fails, you can try checking the IResponse.ConnectionStatus.OriginalException property, which will contain the actual Elasticsearch error.

Passing RequestHeader Play2.1

I have a Problem in compiling play 2.1 application ,in main.scala.html I called javascriptRouters
javascriptRouter("jsRoutes")(
routes.javascript.Authentication.authenticate
For this I have defined (request: play.api.mvc.RequestHeader) on top level
so its working fine now I got request object in this page but when calling
#main("title")
Unspecified value parameter content.
[error] #main(title = "Create Job",status,role){
how to pass request object ????
`
I solved my problem by passing it in the new parenthesis but have a new questions
why it is not working when passed it with content
The first one I understand that whenever I am calling #main I have to passs three string
what does second parenthesis mean (content :Html) are we passing the caller html here
that what does this mean?
#(title:String, status:Option[String],role:String)(content: Html)(implicit request: play.api.mvc.RequestHeader)