Created
January 16, 2019 05:18
-
-
Save srafay/19e0a13fe7e402f0a79715b1ed3f6560 to your computer and use it in GitHub Desktop.
Python Request for form-data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generates request data payload to be sent as 'form-data' | |
REQUEST_FORM_DATA_BOUNDARY = "REQUEST_FORM_DATA_BOUNDARY" | |
FORM_DATA_STARTING_PAYLOAD = '--{0}\r\nContent-Disposition: form-data; name=\\"'.format(REQUEST_FORM_DATA_BOUNDARY) | |
FORM_DATA_MIDDLE_PAYLOAD = '\"\r\n\r\n' | |
FORM_DATA_ENDING_PAYLOAD = '--{0}--'.format(REQUEST_FORM_DATA_BOUNDARY) | |
REQUEST_CUSTOM_HEADER = { | |
'content-type': "multipart/form-data; boundary={}".format(REQUEST_FORM_DATA_BOUNDARY), | |
'Content-Type': "", | |
'cache-control': "no-cache" | |
} | |
def generate_form_data_payload(kwargs): | |
payload = '' | |
for key, value in kwargs.items(): | |
payload += '{0}{1}{2}{3}\r\n'.format(FORM_DATA_STARTING_PAYLOAD, key, FORM_DATA_MIDDLE_PAYLOAD, value) | |
payload += FORM_DATA_ENDING_PAYLOAD | |
return payload | |
# Pass your input as kwargs to the function | |
# Example: | |
import requests | |
API_URL = "www.example.com/verifyuser | |
kwargs = {'ChannelId': channel_id, | |
'ReferenceNumber': reference_number, | |
'AccountNumber': account_numbers, | |
'Cnic': cnic, | |
'MobileNumber': mobile_number, | |
'Otp': otp} | |
# generate payload to be sent as form-data | |
request_data = generate_form_data_payload(kwargs) | |
response = requests.post(API_URL, headers=REQUEST_CUSTOM_HEADER, data=request_data) |
Hello Syed,
Yes, I solved easily using Selenium. Specifically; from selenium.webdriver.common.keys import Keys.
I declare a variable type DATE. And then i do the following:
date = single_date.strftime("%d-%m-%Y") elem = driver.find_element_by_name(The whole datpicker until foo included) elem.clear() elem.send_keys(date) elem.send_keys(Keys.RETURN)
And that's it! if its not cleared let me know!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey sorry I just saw this comment (GitHub doesn't notify you when someone comments on your gists). Were you able to solve your problem? If you did, let me know how so that others facing the same problem could solve it as well.
Thanks! @Camps94