0

I build a service to call API from Python flask. This is my Service

public string CheckStatus(string json)
    {
        Utils log = new Utils();
        string ResponseString = "";
        HttpWebResponse response = null;
        try
        {
            string schedulingAPIUrl = ConfigurationManager.AppSettings["SchedulingAPI_URL"];
            var request = (HttpWebRequest)WebRequest.Create(string.Format(schedulingAPIUrl + "{0}", "CheckStatus"));
            request.Accept = "application/json";
            request.Method = "POST";
            request.Timeout = Timeout.Infinite;
            request.KeepAlive = true;
            var myContent = json;
            
            var data = Encoding.ASCII.GetBytes(myContent);

            request.ContentType = "application/json";
            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            response = (HttpWebResponse)request.GetResponse();
            ResponseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
        }
        catch (WebException ex)
        {
            if (ex.Status == WebExceptionStatus.ProtocolError)
            {
                response = (HttpWebResponse)ex.Response;
                ResponseString = "Some error occurred: " + response.StatusCode.ToString();
            }
            else
            {
                ResponseString = "Some error occurred: " + ex.Status.ToString();
            }
        }
        return ResponseString;
    }

My Service will transfer a parameter is a list of many dictionaries to my API. If the Parameter has an amount of ~ 10000 dictionaries, everything is ok. But If it has to amount to 1 million dictionaries or more, after my API run 8-10minutes, I get an error: "500 InternalServerError".

I use wfastcgi, IIS to deploy my API.

I don't know the reason for the 500 error being from my Service or my API.

  • reconsider before sending millions of data. you should implement streaming api for such large data trasnsfer. – Lei Yang Mar 15 '22 at 02:36
  • I will do that, but when I send data completed and run in 5-10p I just got an error. I will update my post clearly now. – Toan Nguyen Phuoc Mar 15 '22 at 02:44
  • 500 error means there's some unhandled exception(in your c# code) you may need add more logs in server. did you ever check the server log? – Lei Yang Mar 15 '22 at 02:47
  • Yes, I did. The error exist from line code `ResponseString = new StreamReader(response.GetResponseStream()).ReadToEnd();` so I think I can't add more logs in server – Toan Nguyen Phuoc Mar 15 '22 at 02:52
  • if you did check the log, then show the log. there should be errors with call stack trace. – Lei Yang Mar 15 '22 at 02:57
  • did you mean server log? Is it my service log or my server deploy API log? If it is my service log, I know the line exist error ` ResponseString = new StreamReader(response.GetResponseStream()).ReadToEnd();`. If it is my server deploying my API, it does not exist any errors. It's so weird – Toan Nguyen Phuoc Mar 15 '22 at 03:10
  • I know the line exist error --- show the errors. – Lei Yang Mar 15 '22 at 03:16
  • @LeiYang, the error in server log just is: "Some error occurred: InternalServerError" – Toan Nguyen Phuoc Mar 15 '22 at 03:38
  • it is client error, you need paste server error here. – Lei Yang Mar 15 '22 at 03:39
  • I'm sorry so much if my answer and question made you uncomfortable, I'm confused between client error and server error. My server is window 10, so I need to check the window 10 services log? – Toan Nguyen Phuoc Mar 15 '22 at 04:18
  • i'm also confused. if your work flow is c# as client, post to flask, then check flask logs. – Lei Yang Mar 15 '22 at 04:20
  • my flask logs are nothing, I don't give any error log from flask logs, it's so weird. I'm sure I write errors to log if have errors – Toan Nguyen Phuoc Mar 15 '22 at 04:27
  • then check the proxy logs, such as uwsgi if you're using such. – Lei Yang Mar 15 '22 at 04:30
  • I get information in proxy logs: "wfastcgi.py will restart when files in D:\www\SchedulingAPI\app\ are changed" and not show any error – Toan Nguyen Phuoc Mar 15 '22 at 06:11
  • It's seem error from IIS, I get an error when I test API in postman : `The FastCGI process exceeded configured activity timeout` – Toan Nguyen Phuoc Mar 15 '22 at 06:39
  • 1
    ok. so you really need refactor to stream way, instead of possibly increasing timeout/message size. – Lei Yang Mar 15 '22 at 06:40
  • @ToanNguyenPhuoc Please do not use WebRequest, WebClient to make API calls since they are marked as obsolete: https://learn.microsoft.com/en-us/dotnet/core/compatibility/networking/6.0/webrequest-deprecated . Please use the `System.Net.Http.HttpClient` class instead. – Rahul Sharma Mar 15 '22 at 07:44
  • You can use failed request tracking to view detailed error information. – samwu Mar 15 '22 at 09:09

0 Answers0