I am creating a program that gets the steam market prices for various CS:GO items, and compares them to one another. I am having trouble getting the steam market JSON into my program. Market JSON
Here is my code:
using (WebClient webClient = new System.Net.WebClient())
{
WebClient n = new WebClient(); // <-- error on this line
string json = n.DownloadString("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250%20%7C%20Valence%20(Factory%20New");
dynamic array = JsonConvert.DeserializeObject(json);
test.Text = array.lowest_price.ToString(); ;
}
I am getting this error when instanciating WebClient():
An unhandled exception of type 'System.Net.WebException' occurred in
System.dll
Additional information: The remote server returned an error: (500)
Internal Server Error.
Is this even a valid JSON? If not, is there an alternative? I heard backpack.tf has an api as well. Would this be better?
Thanks
Looks like the URL is malformed. I.just tried http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Shadow%20Case and it returned a good response.
Of particular note is the enclosed parenthesis in your URL.
Fixed code:
using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString("http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=P250%20%7C%20Valence%20(Factory%20New)");
dynamic array = JsonConvert.DeserializeObject(json);
var price = array.lowest_price.ToString(); ;
}
Related
I am currently having an issue with the Geocoder API. I keep getting an error, (401) Unauthorized. I am using the app_ID and app_Code assigned to me. I have used these with the mapping functionality without issue.
I am trying to build a web application. I need to retrieve geocoding coordinates for address. I am passing an address into the searchtext parameter for the following Geocoder API: https://geocoder.api.here.com/6.2/geocode.json
using (var w = new WebClient())
{
string jsonData = string.Empty;
string url1 = "https://geocoder.api.here.com/6.2/geocode.json?app_id= <myAppID>&app_code=myAppCode>&searchtext=3003+N+Central+Ave+Phoenix+AZ+85012&gen=9";
Uri myOrigin = new Uri(url1);
string myGeocode = string.Empty;
JObject myObject = new JObject();
jsonData = w.DownloadString(myOrigin); //FAILS HERE
myObject = JObject.Parse(jsonData);
}
I am expecting a json response that contains geocoding coordinates for latitude and longitude.
Issue is looks like with users credentials, please use the correct app_id/app_code for the request from the project page.
https://developer.here.com/projects
Do let us know if you have further issues.
I am trying to send a request on a model on sagemaker using .NET. The code I am using is:
var data = File.ReadAllBytes(#"C:\path\file.csv");
var credentials = new Amazon.Runtime.BasicAWSCredentials("","");
var awsClient = new AmazonSageMakerRuntimeClient(credentials, RegionEndpoint.EUCentral1);
var request = new Amazon.SageMakerRuntime.Model.InvokeEndpointRequest
{
EndpointName = "EndpointName",
ContentType = "text/csv",
Body = new MemoryStream(data),
};
var response = awsClient.InvokeEndpoint(request);
var predictions = Encoding.UTF8.GetString(response.Body.ToArray());
the error that I am getting on awsClient.InvokeEndpoint(request)
is:
Amazon.SageMakerRuntime.Model.ModelErrorException: 'The service
returned an error with Error Code ModelError and HTTP Body:
{"ErrorCode":"INTERNAL_FAILURE_FROM_MODEL","LogStreamArn":"arn:aws:logs:eu-central-1:xxxxxxxx:log-group:/aws/sagemaker/Endpoints/myEndpoint","Message":"Received
server error (500) from model with message \"\". See
"https:// url_to_logs_on_amazon"
in account xxxxxxxxxxx for more
information.","OriginalMessage":"","OriginalStatusCode":500}'
the url that the error message suggests for more information does not help at all.
I believe that it is a data format issue but I was not able to find a solution.
Does anyone has encountered this behavior before?
The problem relied on the data format as suspected. In my case all I had to do is send the data as a json serialized string array and use ContentType = application/json because the python function running on the endpoint which is responsible for sending the data to the predictor was only accepting json strings.
Another way to solve this issues is to modify the python function which is responsible for the input handling to accept all content types and modify the data in a way that the predictor will understand.
example of working code for my case:
var data = new string[] { "this movie was extremely good .", "the plot was very boring ." };
var serializedData = JsonConvert.SerializeObject(data);
var credentials = new Amazon.Runtime.BasicAWSCredentials("","");
var awsClient = new AmazonSageMakerRuntimeClient(credentials, RegionEndpoint.EUCentral1);
var request = new Amazon.SageMakerRuntime.Model.InvokeEndpointRequest
{
EndpointName = "endpoint",
ContentType = "application/json",
Body = new MemoryStream(Encoding.ASCII.GetBytes(serializedData)),
};
var response = awsClient.InvokeEndpoint(request);
var predictions = Encoding.UTF8.GetString(response.Body.ToArray());
I am very much perplexed by the error, "Cannot implicitly convert type string to string[]" in a soap call I am attempting to create. I am using VS2015 in C#. Looking at the code:
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
ServiceReference1.Request req = new ServiceReference1.Request();
req.requestID = "validRequestIDString"; // I get the error here
If I am using Bear SoapUI I have no issues sending the same requestID and getting a valid response.
I am guessing that the error is telling me that the response is an array and not a single string but I know that is incorrect.
Any direction would be helpful. Thank you
How about something like:
request.requestID = new String[] { "validRequestIDString" };
I have consumed the web service in windows application, when pass the request to get response getting an error.
I have used WSE 2.0 to pass the credentials.
public string GetResponse(string sPersonnelAreaCode, string sCompanyCode)
{
try
{
WebReference.RIL_STAR_HCM_QueryEmployeeDetails_serviceagent objService1 = new WebReference.RIL_STAR_HCM_QueryEmployeeDetails_serviceagent();
WebReference.fetchEmployeeListRequestEmployeeList[] objReqs = new WebReference.fetchEmployeeListRequestEmployeeList[1];
WebReference.fetchEmployeeListRequestEmployeeList objReq1 = new WebReference.fetchEmployeeListRequestEmployeeList();
WebReference.fetchEmployeeListResponseEmployeeList[] objResponse = new WebReference.fetchEmployeeListResponseEmployeeList[0];
DataSet dsresult = new DataSet();
objReq1.PersonnelAreaCode = sPersonnelAreaCode;
objReq1.CompanyCode = sCompanyCode.ToString();
UsernameToken token = new UsernameToken("***", "***", PasswordOption.SendPlainText);
objService1.RequestSoapContext.Security.Tokens.Add(token);
objReqs[0] = objReq1;
//In the below line getting that error
objResponse = objService1.fetchEmployeeList(objReqs);
}
}
Can anyone please help me?
This kind of error usually comes when the report server path is not proper. Double check your ReportServerUrl
Also refer Report viewer Error message "client found response content type of '' but expected 'text xml' The request failed with an empty response."
Try setting the ContentType:
objReq.ContentType = "text/xml";
Assuming you're using HttpWebRequest..
I just started playing around with some API's in C#. In my form I had added a service reference http://wsf.cdyne.com/WeatherWS/Weather.asmx. Everything works great and I am able to utilize its library. Now I am trying to use for example http://free.worldweatheronline.com/feed/apiusage.ashx?key=(key goes in here)&format=xml. [I have a key] Now when I try to use it as service reference I am not able to use.
Do I have to call it in my form instead of referencing it? or do some sort of conversion? Also does it matter if its xml or json type?
ASMX is old technology and uses SOAP under the hood. SOAP doesn't tend to work with query string parameters, it takes parameters as part of the message.
ASHX is something different (it could be anything, it's one way to write a raw HTML/XML page in .NET), so you can't transfer the method for calling one to the other. It also won't have a service reference, it's likely you request it via a raw HTTP request. You'll need to consuly the service documentation to discover how to use it.
worldweatheronline doesn't return a SOAP-XML that is consumable by a WebService client. Therefore you should download the response and parse it as done with many REST services.
string url = "http://free.worldweatheronline.com/feed/apiusage.ashx?key=" + apikey;
using (WebClient wc = new WebClient())
{
string xml = wc.DownloadString(url);
var xDoc = XDocument.Parse(xml);
var result = xDoc.Descendants("usage")
.Select(u => new
{
Date = u.Element("date").Value,
DailyRequest = u.Element("daily_request").Value,
RequestPerHour = u.Element("request_per_hour").Value,
})
.ToList();
}
Also does it matter if its xml or json type?
No, at the end you have to parse the response by yourself.
string url = "http://free.worldweatheronline.com/feed/apiusage.ashx?format=json&key=" + apikey;
using (WebClient wc = new WebClient())
{
string json = wc.DownloadString(url);
dynamic dynObj = JsonConvert.DeserializeObject(json);
var jArr = (JArray)dynObj.data.api_usage[0].usage;
var result = jArr.Select(u => new
{
Date = (string)u["date"],
DailyRequest = (string)u["daily_request"],
RequestPerHour = (string)u["request_per_hour"]
})
.ToList();
}
PS: I used Json.Net to parse the json string