[ot][spam]gpt-4 completions
Undescribed Horrific Abuse, One Victim & Survivor of Many
gmkarl at gmail.com
Fri Mar 17 05:00:18 PDT 2023
2023-03-17 07:58:34 {
"input": "A high quality python3 example of asynchronously
dispatching a POST request containing JSON to a server requiring basic
authorization and retrieving the response:"
} ```python
import aiohttp
import asyncio
import base64
import json
async def post_request(url, data, username, password):
auth_string = f"{username}:{password}"
auth_header = base64.b64encode(auth_string.encode()).decode()
headers = {
"Authorization": f"Basic {auth_header}",
"Content-Type": "application/json",
}
async with aiohttp.ClientSession() as session:
async with session.post(url, data=json.dumps(data),
headers=headers) as response:
return await response.text()
async def main():
url = "https://example.com/api"
data = {"key": "value"}
username = "your_username"
password = "your_password"
response = await post_request(url, data, username, password)
print(response)
if __name__ == "__main__":
asyncio.run(main())
```
This example uses the `aiohttp` library to make an asynchronous POST
request with JSON data. The `post_request` function takes the URL,
data, username, and password as arguments, and returns the response
text. The `main` function demonstrates how to call the `post_request`
function and print the response. 16909 ms
More information about the cypherpunks
mailing list