twilio-java icon indicating copy to clipboard operation
twilio-java copied to clipboard

Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

Open mehaksaini2811 opened this issue 1 year ago • 2 comments

Issue Summary

I'm using the code from here to create a custom twilio rest client. Locally it works fine but if I try to connect from my organization's dev server using proxy it throws the error Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

Steps to Reproduce

  1. This is the first step
  2. This is the second step
  3. Further steps, etc.

Code Snippet

// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
import io.github.cdimascio.dotenv.Dotenv;

public class Example {

  public static void main(String args[]) {
    Dotenv dotenv = Dotenv.configure().directory(".").load();
    String ACCOUNT_SID = dotenv.get("ACCOUNT_SID");
    String AUTH_TOKEN = dotenv.get("AUTH_TOKEN");
    String PROXY_HOST = dotenv.get("PROXY_HOST");
    int PROXY_PORT = Integer.parseInt(dotenv.get("PROXY_PORT"));

    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ProxiedTwilioClientCreator clientCreator = new ProxiedTwilioClientCreator(
      ACCOUNT_SID,
      AUTH_TOKEN,
      PROXY_HOST,
      PROXY_PORT
    );
    TwilioRestClient twilioRestClient = clientCreator.getClient();
    Twilio.setRestClient(twilioRestClient);

    VerificationCreator verificationCreator = Verification.creator(verifySid, phoneNumber, deliveryChannel);
     verificationCreator.setCustomCode(code);

    System.out.println(message.getSid());
  }
}

Exception/Log

Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false'). I

If I remove the proxy I get a different error saying

No content to map due to end-of-input
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1]

Technical details:

  • twilio-java version: 10.4.1
  • java version: 21

mehaksaini2811 avatar Sep 27 '24 06:09 mehaksaini2811

I will test this.

sbansla avatar Feb 21 '25 17:02 sbansla

My sense is what's happening here is that you are pointing at a server that is returning HTML instead of JSON. Can you double check what your connection settings are and which URL you're pointing to?

kevinburke avatar Apr 08 '25 13:04 kevinburke