Yelp / yelp-api

Examples of code using our v2 API
http://yelp.com/developers
MIT License
580 stars 1.09k forks source link

YelpSharp C# Issue #152

Closed kushal713 closed 8 years ago

kushal713 commented 8 years ago

Hi, I am running the following Yelp c# call on my local machine and it works perfectly fine:- var results = y.Search(searchOptions).Result;

However, when I host the code on the server, this very line returns the following exception:- Message: One or more errors occurred. Source: mscorlib STackTrace: at 'System.Threading.Tasks.Task.ThrowIfExceptional(Boolean include TaskCancelledExceptions)\r\n at System.Threading.Tasks.Task 1.GetResultCore.......

I have also attached a screenshot of the same. Kindly help me in this as its driving me crazy.

yelperror

mittonk commented 8 years ago

@kushal713 : OK, sounds like your code is pretty good (since it works locally) and this is related to your deployment to the server. I've got a few questions that will help find the issue.

  1. What sort of server? Microsoft Azure, something down the hall managed by IT, etc.
  2. What sort of app framework? Something .NET-ish, etc.
  3. Can your code access other web APIs from your machine? (Getting www.google.com would be enough). Should work.
  4. Can your code access other web APIs from the server? If this fails, the Yelp API isn't the issue and a C# / .NET forum will be able to help more.

From the stacktrace, I have a hunch this might be related to serving multiple requests at once on the web server, something like

kushal713 commented 8 years ago

Hi Ken, Thanks for responding on this. Below are the answers to your questions:-

  1. What sort of server? Microsoft Azure, something down the hall managed by IT, etc. - YES. Its Azure. The OS is Windows Server 2012
  2. What sort of app framework? Something .NET-ish, etc. - YES. Its .NET Framework 4.6
  3. Can your code access other web APIs from your machine? (Getting www.google.com would be enough). Should work. - YES. My application uses Google APIs as well. The call to those APIs are being made successfully.
  4. Can your code access other web APIs from the server? If this fails, the Yelp API isn't the issue and a C# / .NET forum will be able to help more. - YES. My application uses Google APIs as well. The call to those APIs are being made successfully. Also, initially the following link was getting blocked in the browser on the server:-

https://api.yelp.com/v2/search?term=food&location=San+Francisco

But then the IT Team installed some yelp certificates and now it opens fine.

Hope I have answered your questions appropriately. Please let me know if you have any other questions.

kushal713 commented 8 years ago

Also, I am not using Task Parallel Library(TPL) anywhere in my code, as suggested by the link shared by you. Can this be related to the async call?

mittonk commented 8 years ago

Hm, no clean answer yet.

Next:

  1. This error:

Unexpected character encountered while parsing value: <, Path ''...

sounds like you're getting an HTML page instead of a JSON response. What HTTP status code does the response have? 200, 404, 500, etc? What's the response body? You should be able to add diagnostics to your code to show this if it's not visible in your debugger.

kushal713 commented 8 years ago

Yes. I was getting the error even before installing the Yelp certificates. But the InnerException in that case was different. It was a Newtonsoft.Json.JsonTextReader.Read() InnerException then. After installing the certificate, the InnerException has changed from Newtonsoft.Json to mscorlib. But the main error is the same. I figured that the response is HTML instead of JSON, which means the call is not being made properly. But what can be the workaround to this? It cant be a Key issue as it would not be going into Exception. It would just be an INVALID_OAUTH error then,

kushal713 commented 8 years ago

Hi, I debugged the dll and it sends the StatusCode as 'NotAcceptable'. This is the response.Content:-

"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"/>\r\n406 - Client browser does not accept the MIME type of the requested page.\r\n<style type=\"text/css\">\r\n\r\n\r\n\r\n\r\n<div id=\"header\">

Server Error

\r\n<div id=\"content\">\r\n <div class=\"content-container\">
\r\n

406 - Client browser does not accept the MIME type of the requested page.

\r\n

The page you are looking for cannot be opened by your browser because it has a file name extension that your browser does not accept.

\r\n
\r\n\r\n\r\n\r\n"

I see this line in particular in the response:- 406 - Client browser does not accept the MIME type of the requested page.\r\n

The page you are looking for cannot be opened by your browser because it has a file name extension that your browser does not accept.

Can you tell me now if you may be aware of this or a workaround? What MIME type is it?

kushal713 commented 8 years ago

Hi Ken. Any suggestions on the above? Its a bit critical for me.

mittonk commented 8 years ago

@kushal713 : I suspect your .NET server is configured not to accept application/json data, which is what the Yelp API returns.

I'd suggest talking to either whoever runs your .NET server environment (IT?) or a .NET group --- we're getting pretty far into Microsoft server configuration here.

mittonk commented 8 years ago

@kushal713 : What is your application sending as its Accept: header? That should include at least application/json.

Chef-Code commented 8 years ago

What browser are you using? As in regards to the original post involving the error you were receiving... My first assumption was that this had something to do with asynchronous execution conflicts... but again, this is an assumption. Are you using asynchronous code?

mittonk commented 8 years ago

Been quiet, closing issue.