0

I recently deployed my first Flask app using IIS on Windows Server 2019 with wfastcgi.

I'm able to see the website on http:myServerIP:88/, log-in and everything else works. I'm also able to see some JSON data output when accessing some GET routes from remote systems.

However, whenever I try to run Invoke-RestMethod from remote computer, which collects some information and calls the URL of the route of my website to update the info to MongoDB on server, it shows the error 500:

Invoke-RestMethod : 500 Internal Server Error Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
At C:\Users\wk14\Desktop\update2DB.ps1:401 char:8

  • $res = Invoke-RestMethod -Method 'Put' -Uri $url -Body (ConvertTo-Jso ...
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I've tested out the PUT route of my app by hosting it on Flask's dev server, and have the remote computer save its JSON data to a text file, then call the Invoke-RestMethod on my host, and it was able to update the data to MongoDB without issues.

But after deploying the Flask app on IIS, the PUT route just stopped working with the error 500 on remote system.
I've tried looking around in the IIS manager, but still couldn't figure out what the issue is.

Could someone please give me some guidance? Thank you!!

wk14
  • 197
  • 1
  • 7

2 Answers2

0

Powershell does NOT support TLS 1.1 and 1.2.

you can force to use TLS 1.2 by using the below code:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 Invoke-WebRequest -Uri 'https://www.test.com'
Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
  • It gave me this error with my PUT URL using your command: Invoke-WebRequest : 404 Not Found

    Not Found

    The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

    My website is on http:/(myServerIP):88/ , would this security protocol matter?
    – wk14 Mar 11 '21 at 21:26
0

I found out the issue was with my PowerShell script, which had a missing field due to an unexpected issue with my remote computer, therefore Flask route wasn't able to find that field and returned the error..

Such a simple error yet there was no log that showed this directly, and the JSON data I used to push from my local system was from another remote system, which didn't have the missing field..

I now updated my script to handle this when the field cannot be found then insert null.

wk14
  • 197
  • 1
  • 7