I try to authenticate with Firebase using HTTPRequest and GDScript on Godot 4.1.
On the console, I get this error:
login_signup(): HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one. <C++ Error> Condition "requesting" is true. Returning: ERR_BUSY <C++ Source> scene/main/http_request.cpp:116 @ request_raw() <Stack Trace> auth.gd:22 @ login_signup() auth.gd:37 @ _on_button_pressed()
Any idea how to solve this? Thank you.
script with HTTPRequest for Firebase
catafest HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one.
That sounds self-explanatory.
Are you creating a new request before an existing one has completed?
DaveTheCoder right, but don't make anything ... maybe the source code is not good.
I created the variable URL like this and I used it. See this simple source code:
extends Control
var webApiKey = "my_api_key_from_firebase_project"
var signupUrl = "https://identitytoolkit.googleapis.com/v1/accounts:signUp?key="
var loginUrl = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key="
func login_signup(url:String,email:String,password:String):
var http = $HTTPRequest
var data_to_send = {'email':email,'password':password}
var body = JSON.stringify(data_to_send)
var headers = ['Content-Type: application/json']
var _error = await http.request(url, headers, HTTPClient.METHOD_POST, body)
func _on_http_req_completed(_result,response_code,_headers,body):
var response = JSON.parse_string(body.get_string_from_utf8())
if (response_code == 200):
print(response)
else:
print(response._error)
func _on_button_pressed():
var url = signupUrl + webApiKey
var email = $ColorRect/TextEdit.text
var password = $ColorRect/TextEdit2.text
print(password,email)
login_signup(url,email,password)
- Edited
- Best Answerset by catafest
Does the error occur when you press the button a second time before the first request has completed? You could solve that by disabling the button when it's pressed (in _on_button_pressed), and re-enabling it after the request has completed (in _on_http_req_completed).
catafest var _error = await http.request(url, headers, HTTPClient.METHOD_POST, body)
I don't see a reason to use await there. This should be equivalent:
var _error = http.request(url, headers, HTTPClient.METHOD_POST, body)
Also, you should check _error. For example:
if _error != OK:
print_debug("HTTP request error: %d" % _error)
I need to convert this test project from old version to Godot 4.3 version , because has some changes and after I will tested I will come with an result. I have a loot of project in a short range of time and all are in my free time with one-man project.