python script to scan a pdf file using online scanner -
i used code scan multiple pdf files contained in folder online scanner "https://wepawet.iseclab.org/" using scrip.
import mechanize import re import os def upload_file(uploaded_file): url = "https://wepawet.iseclab.org/" br = mechanize.browser() br.set_handle_robots(false) # ignore robots br.open(url) br.select_form(nr=0) f = os.path.join("200",uploaded_file) br.form.add_file(open(f) ,'text/plain', f) br.form.set_all_readonly(false) res = br.submit() content = res.read() open("200_clean.html", "a") f: f.write(content) def main(): file in os.listdir("200"): upload_file(file) if __name__ == '__main__': main()
but after execution of code got following error:
traceback (most recent call last): file "test.py", line 56, in <module> main() file "test.py", line 50, in main upload_file(file) file "test.py", line 40, in upload_file res = br.submit() file "/home/suleiman/desktop/mechanize/_mechanize.py", line 541, in submit return self.open(self.click(*args, **kwds)) file "/home/suleiman/desktop/mechanize/_mechanize.py", line 203, in open return self._mech_open(url, data, timeout=timeout) file "/home/suleiman/desktop/mechanize/_mechanize.py", line 255, in _mech_open raise response mechanize._response.httperror_seek_wrapper: http error refresh: http server returned redirect error lead infinite loop. last 30x error message was: ok
could 1 me problem ?
i think issue mime-type text/plain
set. pdf, should application/pdf
. code change worked me when uploaded sample pdf.
change br.form.add_file
call this:
br.form.add_file(open(f), 'application/pdf', f)
Comments
Post a Comment