1

So i am trying to make a script that will auto upload images to facebook for me using RoboBrowser to navigate the mbasic.facebook.com website and i am getting a strange error when submitting the image form:

Traceback (most recent call last):
  File "C:\Users\Admin\OneDrive\Facebook Project\facebook.py", line 55, in <module>
browser.submit_form(form, submit=form["add_photo_done"])
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\robobrowser\browser.py", line 343, in submit_form
response = self.session.request(method, url, **send_args)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 498, in request
prep = self.prepare_request(req)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 441, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 312, in prepare
self.prepare_body(data, files, json)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 500, in prepare_body
(body, content_type) = self._encode_files(files, data)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 159, in _encode_files
fdata = fp.read()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 23, in decode
  return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 57: character maps to <undefined>

Why would this be? I am guessing it is something to do with how i am handling submitting the image file to the form but i'm stumped as to why. My relevant code is below:

form = browser.get_forms()
form = form[0]
image = os.path.dirname(os.path.realpath(__file__)) + r"\test.png"
form['file1'] = image
browser.submit_form(form, submit=form["add_photo_done"])
print(browser.parsed())

Edit:
I do not believe this is a repost of UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to as i am not reading any files in the code, the error seems to come while submitting the form. In any case I had seen this post already and i could not work out how to use it to solve my issue.

Edwould
  • 11
  • 2
  • Possible duplicate of [UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to ](https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character) – Bram Vanroy Aug 21 '18 at 09:05

1 Answers1

0

Figured out that i need to send an image object and not path to the image. solution code below if anyone is looking at this down the line:

image = open(os.path.dirname(os.path.realpath(__file__)) + r"\test.jpg", 'rb')
Edwould
  • 11
  • 2