locked
Bing Spell Check API v7 - Only Working locally in my MAC but not when I deploy to my AWS EC2 instance (eu-central-1 / Frankfurt) RRS feed

  • Question

  • Hello,

    I have a Ruby on Rails application that uses Bing Spell Check V7 to apply some small corrections in texts. When I run my application locally it works perfectly correcting any spell errores in my text.

    But when I deploy my application to AWS (Amazon) EC2 instance in eu-central-1 region (Frankfurt) all the API calls that I do to Bing Spell Check V7 are returned EMPTY. The response I receive is an OK (200) but the flaggedTokens array is EMPTY.

    The following code (Ruby) is the one that I am using and that works perfectly in my local machine. Any idea on what I can be missing for my deployment on AWS?

        uri = 'https://api.cognitive.microsoft.com'
        path = '/bing/v7.0/spellcheck?'
        params = 'mkt=es-es&mode=proof'


        uri = URI(uri + path + params)
        uri.query = URI.encode_www_form({
            # Request parameters
            'text' => "#{text}"
        })

        key = '<HIDDEN>'

        request = Net::HTTP::Post.new(uri)
        request['Content-Type'] = "application/x-www-form-urlencoded"

        request['Ocp-Apim-Subscription-Key'] = key

        response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
            http.request(request)
        end


    Wednesday, September 26, 2018 12:32 PM

Answers

  • Hi Sergio,

    I tested your code and it worked for me from my Linux desktop with Ruby version: ruby 2.3.1p112

    Is there a way for you to verify the Ruby version on Amazon EC2 instance?  The only thing I can think of it being a Ruby/library difference on Amazon.

    --BEGIN--

    #!/usr/bin/ruby

    require "net/http"
    require "uri"

    uri = 'https://api.cognitive.microsoft.com'
    path = '/bing/v7.0/spellcheck?'
    params = 'mkt=es-es&mode=proof'

    text = 'earhtquake'


    uri = URI(uri + path + params)
    uri.query = URI.encode_www_form({'text' => "#{text}"})

    key = '<HIDDEN>'

    request = Net::HTTP::Post.new(uri)
    request['Content-Type'] = "application/x-www-form-urlencoded"
    request['Ocp-Apim-Subscription-Key'] = key

    response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
    end

    puts response.body

    --END--

    Thanks.

    James

    Thursday, September 27, 2018 6:59 PM

All replies

  • Hi Sergio,

    This is a forum related to Language Understanding Intelligent Service (LUIS), might I suggest that you raise the query on the stack overflow page for Microsoft Cognitive Services? at Microsoft Cognitive Services or you can share the feedback on Cognitive Services User Forum


    Mandar Dharmadhikari

    Thursday, September 27, 2018 12:04 AM
  • Hi Mandar,

    Sure I will post it there.Thanks!

    Sergio

    Thursday, September 27, 2018 1:39 PM
  • Hi Sergio,

    I tested your code and it worked for me from my Linux desktop with Ruby version: ruby 2.3.1p112

    Is there a way for you to verify the Ruby version on Amazon EC2 instance?  The only thing I can think of it being a Ruby/library difference on Amazon.

    --BEGIN--

    #!/usr/bin/ruby

    require "net/http"
    require "uri"

    uri = 'https://api.cognitive.microsoft.com'
    path = '/bing/v7.0/spellcheck?'
    params = 'mkt=es-es&mode=proof'

    text = 'earhtquake'


    uri = URI(uri + path + params)
    uri.query = URI.encode_www_form({'text' => "#{text}"})

    key = '<HIDDEN>'

    request = Net::HTTP::Post.new(uri)
    request['Content-Type'] = "application/x-www-form-urlencoded"
    request['Ocp-Apim-Subscription-Key'] = key

    response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    http.request(request)
    end

    puts response.body

    --END--

    Thanks.

    James

    Thursday, September 27, 2018 6:59 PM
  • Hi James,

    Yes I have tested on a linux machine locally and it works perfectly.

    Do you know how the Area/Zone where the machine is located can affect to this service?

    Reading the Bing Spell Check API v7 reference (https://docs.microsoft.com/es-es/rest/api/cognitiveservices/bing-spell-check-api-v7-reference#query-parameters) says the following:

    "it's available only in the en-US (English-United States), es-ES(Spanish), pt-BR(Portuguese) markets (Note: just beta version for Spanish and Portuguese). For all other markets, set the mode query parameter to Spell."

    So not sure if the zone impacts somehow.... also tried with the mode "Spell" but does not work neither.. maybe a different set on the Query params is needed when running the service from my AWS machine in Frankfurt (Germany) servers...

    This is the Ruby Version on my aws machine --> ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-linux]

    These are the details of the machine --> Linux x86_64 GNU/Linux

    Thanks!

    Sergio

    Monday, October 1, 2018 3:21 PM
  • Hi Sergio,

    For the 'proof' parameter, that shouldn't affect the call unless where the call originates from has a different version of the API.

    From your EU AWS node, can you run: host api.cognitive.microsoft.com or nslookup api.cognitive.microsoft.com and give me the IP address the AWS node detects?

    Also, from hour AWS node, can you try to make a call with the curl command to rule out it being a ruby versioning issue on AWS side?  

    And finally, can you try a GET instead of a POST to see if that works from the AWS node?

    --BEGIN--

    #!/usr/bin/ruby

    require 'net/http'

    uri = URI('https://api.cognitive.microsoft.com/bing/v7.0/spellcheck/')
    uri.query = URI.encode_www_form({
        'text' => 'earhtquake',
        'mode' => 'proof',
        'mkt' => 'es-es'
    })

    request = Net::HTTP::Get.new(uri.request_uri)
    request['Ocp-Apim-Subscription-Key'] = '<HIDDEN>'

    response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
        http.request(request)
    end

    puts response.body

    --END--

    Thanks.

    James


    Monday, October 1, 2018 8:17 PM
  • Hi James - Thanks for all your help

    CURL request was working from the AWS node (on POST and GET methods), so it had to be an issue related with the Ruby version. So I updated the ruby version to 2.4 as I noticed that this was a requirement for this API to work on Ruby.

    Then tested on Ruby 2.4 using GET method but was still not working. Finally managed to get this working using POST method.

    Thanks

    Sergio


    Tuesday, October 2, 2018 3:01 PM
  • Great! I am glad you were able to get this to work!

    Thanks.

    James

    Tuesday, October 2, 2018 3:50 PM