I started getting an ssl/ttl error on my pollen/flu script a few days ago.
Error:
I can still access the json file from flustar.com using cURL and its format hasn't changed. I'm assuming they have changed their security protocol for their https.
I tried adding this line of code
in the script but it didn't seem to help.
Not sure what else I can try to get this to work.
Anyone have any ideas?
Error:
Code:
Exception has been thrown by the target of an invocation.The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
I tried adding this line of code
Code:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
Not sure what else I can try to get this to work.
Anyone have any ideas?
Code:
Imports System.Web.Script.Serialization Sub Main(ByVal Parms As Object) Dim fluIndex As Decimal Dim coughIndex As Decimal Dim strepIndex As Decimal Dim feverIndex As Decimal Try ' Create a WebRequest to the remote site, specifying Referer and UserAgent Dim getRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www.flustar.com/api/forecast/current/cold/80908") getRequest.Referer="https://www.flustar.com/api/forecast/current/cold/80908" getRequest.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" Dim getResponse As System.Net.HttpWebResponse = getRequest.GetResponse() If getResponse.StatusCode = System.Net.HttpStatusCode.OK Then ' Parse the contents from the response to a stream object Dim stream As System.IO.Stream = getResponse.GetResponseStream() ' Create a reader for the stream object Dim reader As New System.IO.StreamReader(stream) ' Read from the stream object using the reader, put the contents in a string Dim contents As String = reader.ReadToEnd() ' Save JSON string into a JSON file My.Computer.FileSystem.WriteAllText(hs.GetAppPath & "\html\json\Flu.json", contents, False) ' Convert JSON string to object Dim jsonData As Object = New JavaScriptSerializer().Deserialize(Of Object)(contents) ' Get Flu Index fluIndex = CDec(jsonData("Location")("periods")("0")("Triggers")("0")(" Index")) ' Get Fever Index feverIndex = CDec(jsonData("Location")("periods")("0")("Triggers")("1")(" Index")) ' Get Strep Index strepIndex = CDec(jsonData("Location")("periods")("0")("Triggers")("2")(" Index")) ' Get Cough Index coughIndex = CDec(jsonData("Location")("periods")("0")("Triggers")("3")(" Index")) End If hs.SetDeviceValuebyRef (4034, fluIndex, True) hs.SetDeviceString(4034, fluIndex.ToString & " out of 12", True) hs.SetDeviceLastChange(4034, now) hs.SetDeviceValuebyRef (4035, feverIndex, True) hs.SetDeviceString(4035, feverIndex.ToString & " out of 12", True) hs.SetDeviceLastChange(4035, now) hs.SetDeviceValuebyRef (4036, strepIndex, True) hs.SetDeviceString(4036, strepIndex.ToString & " out of 12", True) hs.SetDeviceLastChange(4036, now) hs.SetDeviceValuebyRef (4037, coughIndex, True) hs.SetDeviceString(4037, coughIndex.ToString & " out of 12", True) hs.SetDeviceLastChange(4037, now) Catch ex As Exception hs.SetDeviceValuebyRef (4034, -1, True) hs.SetDeviceString(4034, "Error Retrieving Data", True) hs.SetDeviceLastChange(4034, now) hs.SetDeviceValuebyRef (4035, -1, True) hs.SetDeviceString(4035, "Error Retrieving Data", True) hs.SetDeviceLastChange(4035, now) hs.SetDeviceValuebyRef (4036, -1, True) hs.SetDeviceString(4036, "Error Retrieving Data", True) hs.SetDeviceLastChange(4036, now) hs.SetDeviceValuebyRef (4037, -1, True) hs.SetDeviceString(4037, "Error Retrieving Data", True) hs.SetDeviceLastChange(4037, now) hs.writelog("Error", "Error retrieving Flu Data.") End Try End Sub
Comment