Embeddable AI

 View Only

Setting custom headers and user-agent in "analyze" request

  • 1.  Setting custom headers and user-agent in "analyze" request

    Posted Tue November 22, 2022 09:14 AM


    Is it possible to get the NLU API to send custom headers and/or user-agent in the request it makes to the target server URL?
    By target server I mean the one that is serving the content for the URL specified as a name parameter to `analyze` method.
    For example, using Python SDK:

    natural_language_understanding = NaturalLanguageUnderstandingV1(
    headers = {
    'X-Custom-Header': 'Value'
    target_url = "http://myserver.com"
    natural_language_understanding.set_default_headers(headers) # point A
    response = natural_language_understanding.analyze(
    headers=headers, # point B

    neither setting headers in point A nor point B makes the server at "myserver.com" see the custom X-Custom-Header header.

    I am suspecting the set_default_headers and the named param "headers" for "analyze" are meant to send headers to IBM Watson service, not through it.

    The problem I am trying to solve is that some of the target servers I use (where "myserver.com" is in the example) interpret IBM Watson's request as being sent from a bot and reject it not emitting any content. Setting a header would allow me to include extra information for the content server to recognize IBM Waton's request as legitimate.

    Would anyone know if its possible to set headers/user-agent on the request at all?
    Or whether there are better solutions to the problem altogether :)

    Many thanks

    Arunsa Cesonis