4

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

2
  • 1. Please use the formatting guide on the right side of the page when posting questions. 2. Please use Upper Case letters to Begin Sentences and for Proper Nouns, like "I". Commented Apr 7, 2010 at 10:27
  • How could you have asked just the worst answer? Commented Mar 10, 2014 at 14:42

4 Answers 4

26

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Despite the question being a bit strange to begin with, this is the first hit Google gave me for my problem and this is the answer that solved my problem. Thanks.
6

This solution works for me on Ubuntu.

Add the following statement right at the beginning, before all import statements.

# -*- coding: utf-8 -*-`

Similar approach for errors with the term '\xe2'.

Comments

1

Incorrect characters are probably "comma", or "quotes" on line 8. It probably occurred during the "Ctrl + C", "Ctrl + V". ;) You can try rewrite these characters manually.

Comments

-10

You have copied and pasted code with non-ASCII characters. You have an \xc3 character on line 8.

2 Comments

It is just what was given in the message. It is a solution? How can be it solved?
You really should explain reason of it and so a solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.