mast.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:supernovae 作者: astrocatalogs 项目源码 文件源码
def mastQuery(request):
    """Perform a MAST query.

    Parameters
    ----------
    request (dictionary): The Mashup request json object

    Returns head,content where head is the response HTTP headers, and content
    is the returned data.

    """
    server = 'mast.stsci.edu'

    # Grab Python Version
    version = ".".join(map(str, sys.version_info[:3]))

    # Create Http Header Variables
    headers = {"Content-type": "application/x-www-form-urlencoded",
               "Accept": "text/plain",
               "User-agent": "python-requests/" + version}

    # Encoding the request as a json string
    requestString = json.dumps(request)
    requestString = urlencode(requestString)

    # opening the https connection
    conn = httplib.HTTPSConnection(server)

    # Making the query
    conn.request("POST", "/api/v0/invoke", "request=" + requestString, headers)

    # Getting the response
    resp = conn.getresponse()
    head = resp.getheaders()
    content = resp.read().decode('utf-8')

    # Close the https connection
    conn.close()

    return head, content
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号