I have a simple Python script as shown below which accesses a PHP script.
import urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
url="http://192.168.122.1/info.php/"
datagen, headers = multipart_encode({"file": open("123.txt", 'r')})
request = urllib2.Request(url,datagen,headers)
response = urllib2.urlopen(request)
data = response.read();
print data
But I get the following error:
Traceback (most recent call last):
File "sample.py", line 8, in <module>
response = urllib2.urlopen(request)
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1194, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib/python2.7/httplib.py", line 1048, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 1088, in _send_request
self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 1044, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 892, in _send_output
self.send(message_body)
File "/usr/lib/python2.7/httplib.py", line 864, in send
self.sock.sendall(data)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
TypeError: must be string or buffer, not instance
What could be the reason for this? Or is it a problem with my PHP script.
This is my PHP script
<?php
echo "Hello";
?>