i had passed .csv file post request
in api,
input_file = data.get('file', none) input_file datasheet: header = datasheet.readline() ...............
i got error on second line. file type unicode again giving error on third line readline()
>>> "test1.html" fp: ... header = fp.readline() ... traceback (most recent call last): file "<stdin>", line 1, in <module> attributeerror: __exit__ >>>
how read file with stament:
code:
>>> open("test1.html") fp: ... header = fp.readline() ...
check file exits or not before doing process.
use os module
demo:
>>> os.path.isfile("test1.html") true >>> os.path.isfile("nofile.html") false >>>
file upload server via post request in api testing using tastypie
fp = open("c:\sample_datasheet.csv", 'rb') content = fp.read() fp.close() fd ={'file': "c:\sample_datasheet.csv", "content": content} self.asserthttpok(self.api_client.post('api of upload', format='json',\ org_id=2, content_type="multipart/form-data",\ data=fd))
and save content
data
server location in view.
Comments
Post a Comment