How to use the requests.put function in requests

To help you get started, we’ve selected a few requests examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github haiwen / seafile / integration-tests / autosetup.py View on Github external
def create_test_user(cfg):
    data = {'username': ADMIN_USERNAME, 'password': ADMIN_PASSWORD, }
    res = requests.post(apiurl('/auth-token/'), data=data)
    debug('%s %s', res.status_code, res.text)
    token = res.json()['token']
    data = {'password': PASSWORD, }
    headers = {'Authorization': 'Token ' + token}
    res = requests.put(
        apiurl('/accounts/{}/'.format(USERNAME)),
        data=data,
        headers=headers)
    assert res.status_code == 201
github ridi / lightweight-rest-tester / rest_tester / function / __init__.py View on Github external
def _send_request(method, url, params, data, **settings):
        if method == TestMethod.GET:
            return requests.get(url=url, params=params, **settings)
        elif method == TestMethod.PUT:
            return requests.put(url=url, data=data, **settings)
        elif method == TestMethod.POST:
            return requests.post(url=url, data=data, **settings)
        elif method == TestMethod.PATCH:
            return requests.patch(url=url, data=data, **settings)
        elif method == TestMethod.DELETE:
            return requests.delete(url=url, **settings)
        else:
            raise UnsupportedMethodError('Unsupported method: %s' % method)
github apache / couchdb / build-aux / logfile-uploader.py View on Github external
exit(1)

    creds = (lp[0], lp[1])
    doc = build_ci_doc()
    req = requests.post(
        COUCH_URL,
        data=json.dumps(doc),
        auth=creds,
        headers={"Content-type": "application/json"},
    )
    req.raise_for_status()
    req = _tojson(req)
    with open(TARFILE, "rb") as f:
        # ancient versions of requests break if data is iterable
        fdata = f.read()
        req2 = requests.put(
            COUCH_URL + "/" + doc["_id"] + "/" + TARFILE,
            headers={"Content-type": "application/x-gtar"},
            auth=creds,
            params={"rev": req["rev"]},
            data=fdata,
        )
    req2.raise_for_status()
    return req2
github mgeldert / pulse-vtm-ansible / library / krb5conf.py View on Github external
def put(password, name, data):
    response = requests.put(
        "http://localhost:9070/api/tm/5.1/config/active/krb5confs/{}".format(name),
        auth=("admin", password),
        headers={"Content-Type": "application/octet-stream"},
        data=data
    )
    if response.status_code not in [204]:
        response.raise_for_status()
github ansible / ansible / lib / ansible / modules / extras / messaging / rabbitmq_exchange.py View on Github external
)

    # Exit if check_mode
    if module.check_mode:
        module.exit_json(
            changed= changeRequired,
            result = "Success",
            name = module.params['name'],
            details = response,
            arguments = module.params['arguments']
        )

    # Do changes
    if changeRequired:
        if module.params['state'] == 'present':
            r = requests.put(
                    url,
                    auth = (module.params['login_user'],module.params['login_password']),
                    headers = { "content-type": "application/json"},
                    data = json.dumps({
                        "durable": module.params['durable'],
                        "auto_delete": module.params['autoDelete'],
                        "internal": module.params['internal'],
                        "type": module.params['exchangeType'],
                        "arguments": module.params['arguments']
                    })
                )
        elif module.params['state'] == 'absent':
            r = requests.delete( url, auth = (module.params['login_user'],module.params['login_password']))

        if r.status_code == 204:
            module.exit_json(
github sam81 / pychoacoustics / windows_installer / win_compile.py View on Github external
print("###############################")
    print("Publishing")
    print("###############################")
    API_KEY = os.environ["BINTRAY_API_KEY"]

    USERNAME = "sam81"

    URL = "https://api.bintray.com/content/sam81/hearinglab-win/"+ "/pychoacoustics_" + ver + "/" + exeName + "?publish=1"
    parameters = {"publish": "1"}
    headers = {
        "X-Bintray-Package": "pychoacoustics",
        "X-Bintray-Version": ver
    }

    with open(exePath, "rb") as package_fp:
        response = requests.put(
            URL, auth=(USERNAME, API_KEY), params=parameters,
            headers=headers, data=package_fp) 

    print("status code: " + str(response.status_code))
    if response.status_code == 201:
        print("#####################\n Upload successful!")
    else:
        print("#####################\n Upload Unsuccessful.")

    htmlPagePath = "/media/ntfsShared/lin_home/dc/devel/websites/xoom-website/altervista/pychoacoustics/pychoacoustics.html"
    fIn = open(htmlPagePath, "r")
    lns = fIn.readlines()
    fIn.close()

    for i in range(len(lns)):
        if lns[i].strip()[0:73] == '<li> </li>
github mesosphere / marathon-autoscale / marathon-autoscale.py View on Github external
def scale_down_app(self, marathon_app, autoscale_multiplier):
        target_instances=math.ceil(self.appinstances / autoscale_multiplier)
        if (target_instances &lt; min_instances):
            print("No scale, reached the minimum instances of ", min_instances)
            target_instances=min_instances
        else:
            target_instances=target_instances
        if (self.appinstances != target_instances):
            data ={'instances': target_instances}
            json_data=json.dumps(data)
            #headers = {'Content-type': 'application/json'}
            response=requests.put(self.uri + '/service/marathon/v2/apps/'+ marathon_app, json_data,headers=self.headers,verify=False)
            print ('Scale_down_app return status code =', response.status_code)
github idekerlab / heat-diffusion / ndex / client.py View on Github external
def put_multipart(self, route, fields):
        url = self.host + route
        multipart_data = MultipartEncoder(fields=fields)
        if self.debug:
            print("PUT route: " + url)

        headers = {'Content-Type' : multipart_data.content_type,
                   'Accept' : 'application/json',
#                   'Cache-Control': 'no-cache',
                   'User-Agent':userAgent
                   }
        response = requests.put(url, data=multipart_data, headers=headers,auth=(self.username, self.password))
        self.debug_response(response)
        response.raise_for_status()
        if response.status_code == 204:
            return ""
        try:
            result = response.json()
        except ValueError:
            result = response.text
        return result
github qianxiao996 / FrameScan-GUI / Plugins / couchdb / unauth.py View on Github external
def run(url):
        result = ['CouchDB 未授权漏洞', '', '']
        headers = {
            "User-Agent":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50"
        }
        payload = "/itestvuls"
        vulnurl = url + payload
        try:
            req = requests.put(vulnurl)
            vulnurl = url + "/_all_dbs"
            req2 = requests.get(vulnurl, headers=headers, timeout=6, verify=False)
            if r"itestvuls" in req2.text:
                result[2] = '存在'
                result[1]=vulnurl+"\t创建数据库itestvuls"
            else:
                result[2] = '不存在'

        except:
            result[2] = '不存在'
        return result
github tiangolo / full-stack-fastapi-couchbase / {{cookiecutter.project_slug}} / backend / app / app / crud / user.py View on Github external
def insert_sync_gateway(user: UserSyncIn):
    name = user.name
    url = f"http://{config.COUCHBASE_SYNC_GATEWAY_HOST}:{config.COUCHBASE_SYNC_GATEWAY_PORT}/{config.COUCHBASE_SYNC_GATEWAY_DATABASE}/_user/{name}"
    data = jsonable_encoder(user)
    response = requests.put(url, json=data)
    return response.status_code == 200 or response.status_code == 201