py-ms-cognitive
py-ms-cognitive copied to clipboard
header parameters
Looking at the code it does not seem possible to pass an Accept_language header. The header seems just composed of the subscription key. It is possible to set a query parameter to be set to a mkt custom parameter. Is that correct?
Well you're right! Looks like all the various _search()
methods could be updated to take an alternative header dict.
I don't have time to code that up and put it in a pull-request, but if you feel so-inclined, here's your header-dict template:
from collections import OrderedDict
from socket import gethostname, gethostbyname
class CustomHeader(OrderedDict):
def __init__(self):
super(CustomHeader, self).__init__()
self['Ocp-Apim-Subscription-Key'] = raise BaseException('YOU NEED TO CHANGE THIS')
#...the following 2 filled-out header-params aren't necessary,
# but should you choose to render html and/or want local-results, they'll help....
self['User-Agent'] = \
"Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1"
self['X-Search-ClientIP'] = gethostbyname(gethostname())
#
self['X-MSEdge-ClientID'] = None # <<--HIGHLY-SUGGESTED
self['Accept'] = None
self['Accept-Language'] = None
self['X-Search-Location'] = None