-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SendMessage returns null #126
Comments
I fixed the certificate error on that server, but the issue still persists. How can I debug this issue? Is it due to some kind of transport failure (e.g. networking issue?) |
It could be a transport issue. RestSharp eats transport errors, so its hard to debug them. I'd suggest breaking out a tool like Fiddler so you can watch the actually HTTP requests being made by the library to Twilio. This should give you some insite into whether there is a connectivity issue. I'd love to know if you find anything there so I can work on better surfacing these kinds of issues. |
Thanks @devinrader, I'm trying to use fiddler, but I can't see any requests relating to the twilio webservice in the tool - is there anything special I have to to in my code to allow the api to go through the fiddler proxy? |
What OS are you running? Do you see requests in Fiddler to other URL's? Are you trying to make a request to localhost? There shouldn't be anything special you need in your code to make Fiddler work. |
It is Windows Server 2008 R2. I can see plenty of other requests in fiddler. I can also see requests to api.twilio.com if I just browse to it from within (say) chrome |
Are you loading the site you want to test using localhost? If you are you might read this: http://docs.telerik.com/fiddler/observe-traffic/troubleshooting/notraffictolocalhost |
I don't think that could be the problem, on the one hand I can see plenty of requests to localhost in the fiddler output, and on the other hand isn't the twilio API trying to connect outbound to the server api.twilio.com? Aren't we interested in those requests? Could it be because the API request goes via https? Would the API request bypass the fiddler proxy in that case? |
Sample fiddler output shown below at about the time of the issue. The highlighted request is when I went to "https://api.twilio.com" in the chrome browser. |
Its possible this is applicable to you: If it is, you should be able to set the proxy on TwilioRestClient. HTTPS requests should still be logged by Fiddler. |
Based on the screenshots it seems like there is still an issue with the library hitting the server with with HTTPS. You should be seeing two requests like you see on your development machine. I've never see this issue before though. The Twilio library uses RestSharp to make the HTTP requests so there certainly could be an issue in that library. RestSharp itself uses HttpWebRequest to actually make its request. I did a bit of googling for RestSharp and SSL and found a number of people talking about authentication failures. I wonder if thats what you are running into. Depending on how far the rabbit hole you want to go I think you've got a couple of options all of which might end up surfacing the root cause:
|
I am trying to use the RestSharp API directly and came up against the following issue that "AsString()" in the following code is not defined:
I presume it is an extension method, but I can't see where it is defined. For now I just went with this, which I thought was probably right:
|
I believe you can just add:
|
So I did some more work, and found that the HTTP StatusCode from the request is coming back as 0. From what I can tell, this should only happen if the request is cancelled before going anywhere, possibly some kind of firewall interference (http://stackoverflow.com/questions/3825581/does-an-http-status-code-of-0-have-any-meaning). This is what I added:
#if FRAMEWORK
...
In my log, I saw the following: TwilioSender.SendMessage ... |
What happens if you move this code:
Out of the if block, right after this line of code:
Is the ErrorException property populated? |
Hi Devin, I tried this and got some interesting results. The first attempt, the message send actually succeeded. I don't know why this happened, I hadn't made any configuration or code changes that would make me expect it to have worked from that machine. I tried it again and this time it failed as it had been doing last week. I got the following results in the log: |
Yes, it could. Is the FortiGate your corporate firewall? I don't know enough about firewalls to be able to give you much advice, but Twilios SSL cert should be a Thawte cert as your seeing on your dev machine. |
I'll have to do some investigation, the machine with the problem is in our India office so I'm not sure how they have it set up there. |
Hi Devin, I have figured out that the problem is that the fortigate certificate was not trusted by the local machine account - although I had trusted it by the logged in user, IIS was running as a different user. By trusting the root certificate at the local machine account, it enabled the service to work correctly. |
In order to fix the issue where SendMessage is returning null, do you think this kind of thing would be appropriate to add? Just basically to drag out information regarding the network issue:
... And then in the calling code:
Or would it "fit" in the existing RestException? |
Possibly. Though for errors like transport and network exceptions (eg DNS resolution failure, request time out, etc) I'd prefer to find a way to just bubble out an underlying exception if there is one instead of checking for that status code, since that's not really a status code. When the error happens, are you seeing it get caught by RestSharp and exposed via the ErrorException property? IIRC that should be getting populated if things like transport or network errors cause HttpWebRequest to throw an exception. Either here if its bubble out as a WebException: Sync: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Http.Sync.cs#L196-L213 or here is its any other exception: Sync: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Http.Sync.cs#L181-L191 The thing I may need to figure out is if checking for that exception in OnBeforeDeserialization is the right place for it. |
Hi Devin, the ErrorException property is being populated - it is a WebException - just check the screenshot here (#126 (comment)). It looks like it would generally be populated in either of those two places |
OK, since this has somewhat turned into a different issue than SendMessage being null I'm going to close this and open up another tissue for exposing the underlying transport exceptions. |
On one of our machines, the
message
result is returned as null. This seems to be due to the security certificate for the server "https://api.twilio.com/" not being trusted.I am using Twilio.Api version 3.4.1.0 and RestSharp version 104.4.0.0.
See also:
http://stackoverflow.com/questions/14614335/twilios-twiliorestclient-sendsmsmessage-returns-null
The text was updated successfully, but these errors were encountered: