Raised This Month: $23 Target: $400
 5% 

REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)


Post New Thread Reply   
 
Thread Tools Display Modes
BlackFart
Junior Member
Join Date: Feb 2021
Old 02-15-2021 , 08:40   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #91

Thanks for your answer

Quote:
Mind if I ask, how are you recording your demos in JPEG?
For the example, I started to try to upload a file (in fact, it's not even a picture, it's just text) (in fact 2, I see no problem in saving demos with a different extension, it's just a headache to find your way around ha ha)

Quote:
But you're still trying to upload "data/image.jpg" file, which with the BuildPath / Path_SM one would be the file @ "addons/sourcemod/data/image.jpg"?

... Is there any file at all, with the path "addons/sourcemod/data/image.jpg"?
Yes, the file exists As a test, I ignore the demo file (and yes, there is one at least, so I go in the loop. Best debugger proof, my prints)

Quote:
In the end, with no errors, chances are the upload works just fine, and that it is your web url that may not work as expected.

... Is there anything running at all, on localhost, port 8080, and if so, what is the code over there?
No, it's not the right URL, but for the purpose of this post (in the forum, not http xD), I just changed the url (wouldn't be helping if I had wrote localhost:8081/api/v1/demo/upload)

And, I got nothing (my API is working well for other routes). If the route doesn't match, it would still be logged, as long as I hit localhost:8081

Here is the same code simplified :
Code:
HTTPClient httpClient;

public void UploadPicture()
{
    httpClient = new HTTPClient("localhost:8081/api/v1/demo/");

    char picturePath[PLATFORM_MAX_PATH];
    BuildPath(Path_SM, picturePath, sizeof(picturePath), "data/image.jpg"); 

    httpClient.UploadFile("upload", picturePath, OnPictureUploaded); 
}

void OnPictureUploaded(HTTPStatus status, any value)
{
    // never called
    if (status != HTTPStatus_OK) {
        PrintToServer("Noooooooooooooo %d", status);
        return;
    }
    PrintToServer("Upload complete");
}
But, as I said in the edit, even in the first example, where we get a simple json, it's not working. The callback is never called

Last edited by BlackFart; 02-15-2021 at 08:54.
BlackFart is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 02-15-2021 , 09:35   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #92

You are missing http:// in your URL. I would also check your sourcemod/logs folder for errors.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
I do not provide support in PMs. Please use the forum thread.

Last edited by DJ Tsunami; 02-15-2021 at 09:36.
DJ Tsunami is offline
BlackFart
Junior Member
Join Date: Feb 2021
Old 02-15-2021 , 10:20   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #93

Quote:
Originally Posted by DJ Tsunami View Post
You are missing http:// in your URL.
I don't think this is the issue as I specified the port in the url

Quote:
Originally Posted by DJ Tsunami View Post
I would also check your sourcemod/logs folder for errors.
Nothing looks like linked to my issue (only info from maps etc)

Anyway, the extension is loaded correctly.
The plugin is listed loaded in the plugins list from sm too.
When I reload it I got prints next to the httpClient.`methode`("blabla", callBack)
But, I got no prints in the callback, even with this example :

I literally recreate a new plugin with the exact same code as your example (with just one more print) :
PHP Code:
#include <sourcemod>
#include <ripext>

HTTPClient httpClient;

public 
void OnPluginStart()
{
    
httpClient = new HTTPClient("https://jsonplaceholder.typicode.com");

    
httpClient.Get("todos/1"OnTodoReceived);
}

void OnTodoReceived(HTTPResponse responseany value)
{
    
PrintToServer("test please print");
    if (
response.Status != HTTPStatus_OK) {
        
// Failed to retrieve todo
        
return;
    }

    
// Indicate that the response is a JSON object
    
JSONObject todo view_as<JSONObject>(response.Data);

    
char todoTitle[256];
    
todo.GetString("title"todoTitlesizeof(todoTitle));

    
PrintToServer("Retrieved todo with title '%s'"todoTitle);

It's loaded correctly, and when I (re)load it, I still have no print from the callback

Last edited by BlackFart; 02-15-2021 at 10:21.
BlackFart is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 02-15-2021 , 11:04   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #94

I did the same with version 1.2.3 and it works fine:
Quote:
sm plugins reload ripext-test
[SM] Plugin REST in Pawn - Tests reloaded successfully.
test please print
Retrieved todo with title 'delectus aut autem'
Maybe try another HTTP extension like SteamWorks to see if it really is an issue with REST in Pawn, or if there is an issue with your server. I'm not really sure what could cause it not to work.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
I do not provide support in PMs. Please use the forum thread.
DJ Tsunami is offline
BlackFart
Junior Member
Join Date: Feb 2021
Old 02-15-2021 , 11:41   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #95

Yes, I'm 99% sure I did something wrong, but what...

I tried others, it was working well, there was just no native function to upload files...
This is my sourcemod version :
Code:
 SourceMod Version Information:
    SourceMod Version: 1.10.0.6502
    SourcePawn Engine: 1.10.0.6502, jit-x86 (build 1.10.0.6502)
    SourcePawn API: v1 = 5, v2 = 12
    Compiled on: Dec 18 2020 04:15:26
    Built from: https://github.com/alliedmodders/sou...commit/617fb77
    Build ID: 6502:617fb77
I unloaded all the exts (but yours and BinTools), same for the plugins, but it's still not working...
I tried with older version of your extension, same issue...

I was then listening to my network interface for any http request while reloading the plugin, still nothing...
I really don't know what could I try/test/check more to get this working...

Last edited by BlackFart; 02-15-2021 at 12:22.
BlackFart is offline
BlackFart
Junior Member
Join Date: Feb 2021
Old 02-17-2021 , 17:14   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #96

Well, let me know if I did it wrong, I'm not used to develop/debug in c++...
I recompiled your extension, and I tried to make some LogMessage for debugging (I'm really not used to debug in c++, even less as an extension for sourcemod...)

From what I've seen, it looks like "AddRequestToQueue" is called correctly, requests are pushed in the queue.
But, "AsyncPerformRequests" doesn't seems to be ever called ? (I put a log at the beginning)

The return value of "uv_async_init(g_Loop, &g_AsyncPerformRequests, &AsyncPerformRequests);" is 0, so it should be working ?

Could you tell me what should/could I do to investigate further, please ?

I'm on a VM running linux, as a windows host (I don't know if this changes something, but I saw there are 2 "uv_async_init" functions, one in libuv/srx/unix and another one in libuv/srx/win, I tried to modify the return value to be sure it calls the good one, but by doing that, my server keep crashing)

Thank you for your time and your help

Last edited by BlackFart; 02-18-2021 at 04:11.
BlackFart is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 02-18-2021 , 11:42   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #97

Which game is your server running, and what Linux distribution and version are you using?

I can send a debug version for Linux that prints everything that happens during the HTTP request, but if it never calls AsyncPerformRequests, then I assume the issue is with libuv, and it doesn't even perform the HTTP request.

I see a new version of libuv was just released, so I can try updating that to see if it helps. As for debugging, I would indeed put a LogMessage before line 180, 196 and 201 in extension.cpp to check if requests are added to the queue, if the queue is processed and if requests are added to the completed queue.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
I do not provide support in PMs. Please use the forum thread.
DJ Tsunami is offline
BlackFart
Junior Member
Join Date: Feb 2021
Old 02-18-2021 , 13:08   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #98

Quote:
Originally Posted by DJ Tsunami View Post
Which game is your server running, and what Linux distribution and version are you using?
It is running CSGO (through LinuxGSM https://docs.linuxgsm.com/guides/sourcemod-csgo-server) on an Ubuntu 18.04.4 LTS.

Quote:
Originally Posted by DJ Tsunami View Post
I can send a debug version for Linux that prints everything that happens during the HTTP request, but if it never calls AsyncPerformRequests, then I assume the issue is with libuv, and it doesn't even perform the HTTP request.
TBH, as I'm far from beeing a pro in C++, idk if "myself" and everything else is correctly setuped for working in the callback ? (in short, could they be called, but the prints aren't working there ?) I'd be glad to have this version (or if you could explain me how to build it)

Quote:
Originally Posted by DJ Tsunami View Post
As for debugging, I would indeed put a LogMessage before line 180, 196 and 201 in extension.cpp to check if requests are added to the queue, if the queue is processed and if requests are added to the completed queue.
Nothing is printed at the start of FrameHook or AsyncPerformRequests

Thank you for wasting your time on my issue
BlackFart is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 02-20-2021 , 07:24   Re: REST in Pawn 1.2 - HTTP client for JSON REST APIs (Updated 2021/02/07)
Reply With Quote #99

Quote:
Originally Posted by BlackFart View Post
Nothing is printed at the start of FrameHook or AsyncPerformRequests
If a LogMessage at the top of FrameHook doesn't spam your log file or the server console, then your game frame hook isn't firing, which explains why requests aren't processed.

If it's a public server and you're willing to give me FTP and RCON access so I can check some things and debug it myself, you can PM me here on the forum.

Edit: the issue turned out to be hibernation
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
I do not provide support in PMs. Please use the forum thread.

Last edited by DJ Tsunami; 02-20-2021 at 09:07.
DJ Tsunami is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:33.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode