Non-ASCII character Syntax Error in Python while calling URL
Question: How can data can be sent to the server?

For example, I have retrieve MAC address, so I want send to the server (e.g.
<http://211.21.24.43:8080/data?mac=00-0C-F1-56-98-AD>)

I found this snippet on the Internet:

    
    
    from urllib2 import Request, urlopen
    from binascii import b2a_base64
    
    def b64open(url, postdata):
      req = Request(url, b2a_base64(postdata), headers={'Content-Transfer-Encoding': 'base64'})
      return urlopen(req)
    
    conn = b64open("http://211.21.24.43:8080/data","mac=00-0C-F1-56-98-AD")
    

but when I run it, I get:

    
    
    File "send2.py", line 8
    SyntaxError: Non-ASCII character '\xc3' in file send2.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
    

Can anyone help me send data to the server?

Thanks in advance


Answer: put the encoding at the top of .py file

example:

    
    
    #!/usr/bin/env python
    #coding: utf8 
    import os
    ...
    

This probably happened because you copied/pasted some unicode character that
is not visible in your text editor.

