Skip to content

JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. #118

Description

@baudii

Снимок экрана 2024-03-14 205601

I have no idea what this is. Can anyone help?
I didn't change anything in the code. Purely empty project, imported openAI package, added my API key etc., opened sample scene "ChatGPT", pressed "Play" and sent a message. And it happens every single time. So I couldn't get a single request through.
EDIT:
Ok, found out that the problem is with this method:

private async Task<T> DispatchRequest<T>(string path, string method, byte[] payload = null) where T: IResponse
{
    T data;
    
    using (var request = UnityWebRequest.Put(path, payload))
    {
        request.method = method;
        request.SetHeaders(Configuration, ContentType.ApplicationJson);
        
        var asyncOperation = request.SendWebRequest();

        while (!asyncOperation.isDone) await Task.Yield();
        data = JsonConvert.DeserializeObject<T>(request.downloadHandler.text, jsonSerializerSettings);
    }
    
    if (data?.Error != null)
    {
        ApiError error = data.Error;
        Debug.LogError($"Error Message: {error.Message}\nError Type: {error.Type}\n");
    }

    if (data?.Warning != null)
    {
        Debug.LogWarning(data.Warning);
    }
    
    return data;
}

this variable: request.downloadHandler.text
returns a whole html page in a string and not a JSON file

EDIT 2
This is the html page I got:
image
Everything makes sense now since OpenAI doesn't work in Russia. You need a VPN to gain access. I guess, additional check of the response and dedicated error message wouldn't hurt this project.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions