import requests
req = requests.post('http://example.in/phppage.php', data = {'device_id':220,'tank_type':1,'level_pct':78,'water_flow':0,'water_over_flow':0})
print("HTTP Connection Status::"+str(req.status_code))
当我运行此代码时,它显示 http连接状态404 。怎么了?
答案 0 :(得分:0)
# importing the requests library
import requests
# defining the api-endpoint
API_ENDPOINT = "http://pastebin.com/api/api_post.php"
# your API key here
API_KEY = "XXXXXXXXXXXXXXXXX"
# your source code here
source_code = '''
print("Hello, world!")
a = 1
b = 2
print(a + b)
'''
# data to be sent to api
data = {'api_dev_key':API_KEY,
'api_option':'paste',
'api_paste_code':source_code,
'api_paste_format':'python'}
# sending post request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)
# extracting response text `enter code here`
pastebin_url = r.text
print("The pastebin URL is:%s"%pastebin_url)