0

I am trying to get information from the Scopus API ( made for python ), but i'm using C# mvc ( have to ). I am to the point that thats to the api Url : "https://api.elsevier.com/" and api key "3b...", i try to make a request this way :

private readonly ScopusSearchClient apiClient = new ScopusSearchClient("https://api.elsevier.com/", "3b...");

Where ScopusSearchClient refers to :

public ApiClient(string apiUrl, string apiKey)
    {
        _apiUrl = apiUrl;
        _apiKey = apiKey;
        _httpClient = new HttpClient
        {
            BaseAddress = new Uri(_apiUrl)
        };
    }

(ScopusSearchClient is linked to ApiClient which allows me to do that).

I then try and execute an actual request through :

var scopusSearchResult = await apiClient.GetAsync<SearchResults<Scopus>>("content/search/scopus", "query=AF-ID(Harvard Medical School 3000604");

Which is the function :

public async Task<T> GetAsync<T>(string endpoint, string parameters = null) where T : HttpStatusResource
    {
        HttpResponseMessage httpResponseMessage = await _httpClient.GetAsync(Utilities.GenerateRequestUri(_apiUrl, endpoint, _apiKey, parameters));
        string strContent = await httpResponseMessage.Content.ReadAsStringAsync();
        var result = JsonConvert.DeserializeObject<T>(strContent);
        result.IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
        result.StatusCode = httpResponseMessage.StatusCode;
        return result;
    }

The problem is, as I connect I receive the error :

A connection attempt failed because the connected party did not respond properly beyond a certain time or an established connection failed because the connection host did not respond 104.XX.XX.XX:XXX

And it comes from the line

var scopusSearchResult = await apiClient.GetAsync<SearchResults<Scopus>>("content/search/scopus", "query=AF-ID(Harvard Medical School 3000604");

In the controller.

Does anybody have any idea of what is going on ? Thank you very much, Gauthier

  • It looks like you are using the nuget package Scopus.Dotnet.Client (https://github.com/arslanaybars/Scopus.Dotnet.Client). Can you verify that the test code within this repo works on your machine too? – KingOfArrows Apr 13 '21 at 12:20
  • You can also use a free tool like Fiddler to view incoming and outgoing http requests. Try running this when you call this code to see what request is being sent out. Maybe the request is being formed incorrectly. – KingOfArrows Apr 13 '21 at 12:27
  • Hello, I'm having troubles starting the tests, as I start them, the test window just says that they were not executed, without any reasons. Any tips on that too ? Would help getting further indeed. – Gauthier Adrien Apr 13 '21 at 12:39
  • 1
    Please remove that API key and get a new one, you don't want to include these in your post. – Trevor Apr 13 '21 at 12:43
  • Can you put a breakpoint in the test and debug the unit test. Surely the unit tests should run when run as a test. – KingOfArrows Apr 13 '21 at 12:46
  • Thank you I edited it and will create a new one later – Gauthier Adrien Apr 13 '21 at 12:47
  • @KingOfArrows I was able to run the tests, the async function goes through and works, but not the non-async one, send a an error with parsing the result ( but I'm using the async one so that's not the problem i'm facing ) – Gauthier Adrien Apr 13 '21 at 12:48
  • Ok so it looks like it does communicate to Scopus with that data. Can you try taking the GetAsync code from the Async test and using that in your MVC code. If that works, then we know that this library works and the data being passed in is the cause. – KingOfArrows Apr 13 '21 at 13:05
  • It is exacly what I did an yet the same problem is still on... The tests working and not my request is very strange :( – Gauthier Adrien Apr 13 '21 at 13:10
  • By the way, I tried through google directly to put my api key, and the query, and I got the xml result, so the data passed shouldn't be the problem here :/ – Gauthier Adrien Apr 13 '21 at 13:13

1 Answers1

0

It was in the end a problem of firewall, blocking some IPs, including the one of the URL which we are querying to get information from the API. Unblock it throught the firewall !