Skip to content
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

在某一台电脑上发送失败,显示Newtonsoft.Json相关异常 #20

Open
IIIThSoul opened this issue Mar 8, 2023 · 2 comments
Open

Comments

@IIIThSoul
Copy link

错误日志如下,请问是什么问题?在别的电脑上都可以,在一台新电脑上已发送就报这个错误。

[21:01:30.655 ] [ ERROR ] Read Response Failed
[ 21:01:30.655 ] [ ERROR ] Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Button.OnClick => Control.OnClick => FormMain.button1_Click
[ 21:01:30.666 ] [ ERROR ] 在 AlibabaCloud.OpenApiClient.Client.DoRequest(Params params_, OpenApiRequest request, RuntimeOptions runtime)
在 AlibabaCloud.OpenApiClient.Client.CallApi(Params params_, OpenApiRequest request, RuntimeOptions runtime)
在 AlibabaCloud.SDK.Dysmsapi20170525.Client.SendSmsWithOptions(SendSmsRequest request, RuntimeOptions runtime)
在 DTS.FormMain.button1_Click(Object sender, EventArgs e)
[ 21:01:30.666 ] [ ERROR ] Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Button.OnClick => Control.OnClick => FormMain.button1_Click

@Outofnothing
Copy link

Outofnothing commented Apr 24, 2023

我也遇到了类似的问题,关键代码来自OpenAPI Explorer生成的代码,如下

AlibabaCloud.OpenApiClient.Client client = new AlibabaCloud.OpenApiClient.Client
(
    new Config
    {
        // 必填,您的 AccessKey ID
        AccessKeyId = Options.OssAccessKeyId,
        // 必填,您的 AccessKey Secret
        AccessKeySecret = Options.OssAccessKeySecret,
        Endpoint = Options.OssEndPoint
    });
  Params params_ = CreateApiInfo();
  // query params
  Dictionary<string, object> queries = new Dictionary<string, object>() { };
  queries["DurationSeconds"] = duration;
  queries["RoleArn"] = Options.OssArn;
  queries["RoleSessionName"] = uid;
  // runtime options
  RuntimeOptions runtime = new RuntimeOptions();
  OpenApiRequest request = new OpenApiRequest
  {
      Query = AlibabaCloud.OpenApiUtil.Client.Query(queries),
  };
  var response = await client.CallApiAsync(params_, request, runtime);

问题出在最后一行

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at AlibabaCloud.OpenApiClient.Client.DoRequest(Params params_, OpenApiRequest request, RuntimeOptions runtime)

后面发现是我的EndPoint填错了,我正在通过STS获得临时访问凭证以访问OSS,错误地将EndPoint填成了OSS的,正确的应当是STS的。修改之后问题解决。

我猜测该问题的原因是访问API时出错,重定向到了一个HTML界面,JSON解码该HTML时 出错。

SDK应该考虑这种问题,抛出更有意义的异常。

@TsinghuaDream
Copy link

好的 我们评估下这个优化需求。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants