Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with special Caracters "ä", "ö", "ü" in form fill function #32

Closed
sgaechter opened this issue Jan 30, 2019 · 5 comments
Closed

Comments

@sgaechter
Copy link

If I fill a Form with the following Code, special Caracters won't be transferred correctly:
def sendsms():
pr = options[predialstr.get()]
nr = handynumber.get()
txtc = smstext.get("1.0",END)
txt = txtc.strip()
br.set_handle_robots( False )
br.addheaders = [('User-agent', 'Firefox')]
br.open( "http://www.die-startseite.ch/Bern/" )
br.select_form( 'smsBooster' )
br.form[ 'intlPrefix' ] = [str(pr)]
br.form[ 'SMSEingabe' ] = str(nr)
br.form[ 'smsMessage' ] = txt #Error with special swiss Caracters..
br.submit()
resp = br.response()
print(resp)
messagebox.showinfo('Info', 'SMS mit dem Text %s wurde an %s versendet' % (txt, pr + nr))
delFields()

I already attached the Line with utf-8 on my Script:

-- coding: utf-8 --

But somehow it won't pass the Infos corectly to the webform.
Attached the whole Python-Code

free-sms.txt

@amotl
Copy link
Contributor

amotl commented May 11, 2019

Dear @sgaechter,

as I can see from the charset encoding of the page you are referencing

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

you should probably encode the form field values appropriately like

self.browser['smsMessage'] = txt.encode('iso-8859-1')

If you are still running on Python 2, everything should work then. Wenn running on Python 3 already, you will most likely need the small update from #43.

With kind regards,
Andreas.

@kovidgoyal
Copy link
Contributor

You dont need to manually encode values any more. mechanize will automatically encode unicode strings in the encoding of the host HTML document when submitting the form.

@amotl
Copy link
Contributor

amotl commented May 12, 2019

Dear @kovidgoyal,

thank you so much, this was exactly the functionality I have been looking for but apparently was missing from mechanize yet and would have been beyond my current scope to implement -- as my mind obviously lacks important knowledge about the intrinsic details of the code base.

We have been able to give it a test drive right away (frankheider/ip-navigator-py3.6@ef186481) and would like to confirm that this works like a charm.

That was quick, you rock!

With kind regards,
Andreas.

@kovidgoyal
Copy link
Contributor

You're welcome, I had somehow missed this bug report, thanks for
bringing it to my attention.

@sgaechter
Copy link
Author

Dear all.
Thanks @amotl for your help. The project i've tested mechanize went a little behind since my bug report. Thanks @kovidgoyal for your fix. I'll test it tomorrow. Regards sgaechter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants