adv_doris_stream_load.py 911 Bytes
Newer Older
chenyuanjie committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import requests
from requests.auth import HTTPBasicAuth
import base64


def stream_load(data):
    database, table = 'adv', 'sp_customer_search_target_report_copy'
    username, password = 'root', ''
    url = 'http://192.168.10.218:18030/api/%s/%s/_stream_load' % (database, table)
    headers = {
        'Content-Type': 'text/plain; charset=UTF-8',
        'format': 'csv',
        "column_separator": ',',
        'Expect': '100-continue',
        'Authorization': 'Basic ' + base64.b64encode((username + ':' + password).encode('utf-8')).decode('ascii')
    }
    auth = HTTPBasicAuth(username, password)
    session = requests.sessions.Session()
    session.should_strip_auth = lambda old_url, new_url: False  # Don't strip auth

    resp = session.request(
        'PUT', url=url,
        data=data,
        headers=headers, auth=auth
    )

    print(resp.status_code, resp.reason)
    print(resp.text)
wangrui committed
29