in my web app, I use werkzeug to listen and process requests. In one of the functionalities, I need to listen to request(say from A) and send an http put request to another server (B), then after I get response from B, I respond A an response.
I am not very familiar with werkzeug, and not sure if it has ability to send out requests, so I used httplib to send requests.
But I am getting errors.
There are a lot of moving parts, I am wondering the following:
1. does werkzeug have ability to send out requests
2. what is the cause of the error
Appreciate any help.
Code:
def complete(self, request):
if request.method == 'GET':
location_id = self.extract_param_value(request,'location_id');
status_code = self.extract_param_value(request,'status_code');
req_url = something;
jsonData = { 'data' : {'status' : status_code, 'id': location_id}};
jsonDataDump = json.dumps(jsonData);
#send request to B
connection = httplib.HTTPConnection(HOST, timeout=5);
body_content = jsonDataDump;
headers = {"Content-type": "application/json", "Accept": "text/plain"};
connection.request('PUT', req_url, body_content, headers); #error occurs here
result = connection.getresponse();
connection.close();
#return response to A
response = Response(status=200);
return response;
Error:
1**.1**.1**.** - - [30/Dec/2011 03:06:57] "GET //complete?location_id=615201308&status_code=LIVE&message=fine HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/ec2-user/y_ws.py", line 381, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/lib/python2.6/site-packages/Werkzeug-0.8.1-py2.6.egg/werkzeug/wsgi.py", line 411, in __call__
return self.app(environ, start_response)
File "/home/ec2-user/y_ws.py", line 377, in wsgi_app
response = self.dispatch_request(request);
File "/home/ec2-user/y_ws.py", line 98, in dispatch_request
return getattr(self, endpoint)(request, **values)
File "/home/ec2-user/y_ws.py", line 184, in complete
connection.request('PUT', y_req_url, body_content, headers);
File "/usr/lib64/python2.6/httplib.py", line 914, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.6/httplib.py", line 951, in _send_request
self.endheaders()
File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
self._send_output()
File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
self.send(msg)
File "/usr/lib64/python2.6/httplib.py", line 739, in send
self.connect()
File "/usr/lib64/python2.6/httplib.py", line 720, in connect
self.timeout)
File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
raise error, msg
error: [Errno 111] Connection refused
Werkzeug is not a library for making HTTP requests, use httplib (as in your example)
Check with curl if the request succeeds from the host machine to rule out network issues. The error you are getting is general network error.
Related
I'm trying to download a file from Firebase Storage via the Flask app.
The target URL works on browser and when I hardcode it.
However, when I pass the target URL from the frontend as a parameter, it says urllib.error.HTTPError: HTTP Error 403: Forbidden.
Frontend Code (JavaScript)
async function testTriggerLocalFunction(downloadURL) {
const response = await fetch(
// downloadURL is a string like "https://firebasestorage.googleapis.com...."
"http://127.0.0.1:5001?audioURL=" + downloadURL
);
// console.log(response);
}
Backend Code (Flask)
#app.route('/')
def handle_request():
result = analyze(request.args.get("audioURL"))
def analyze(audioURL):
# Download sound file
# url = audioURL
input_name = "input.wav"
input_path = get_file_path(input_name)
# 403 error when audioURL passed from url parameter passed!
urllib.request.urlretrieve(audioURL, input_path)
# But it will work if I do something like "audioURL = "https://firebasestorage.googleapis.com...."
Possible error points
Maybe you lack proper authorization?
Maybe you lack a proper header?
these two seem unlikely because the code works when the URL is hardcoded.
URL encoding?
This PHP question has some URL encoding problem but I'm not sure if this applies to me.
What else can be causing this problem?
127.0.0.1 - - [09/Dec/2021 14:08:59] "GET /?audioURL=https://firebasestorage.googleapis.com/MY_TARGET_AUDIO_URL" 500 -
Traceback (most recent call last):
File "/Users/leochoo/.virtualenvs/py-vocal-journal/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/leochoo/.virtualenvs/py-vocal-journal/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
response = self.handle_exception(e)
File "/Users/leochoo/.virtualenvs/py-vocal-journal/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "/Users/leochoo/.virtualenvs/py-vocal-journal/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/leochoo/.virtualenvs/py-vocal-journal/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/leochoo/.virtualenvs/py-vocal-journal/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/Users/leochoo/dev/vocal-journal/backend/playground/py-vocal-journal/app.py", line 68, in handle_request
result = analyze(request.args.get("audioURL"))
File "/Users/leochoo/dev/vocal-journal/backend/playground/py-vocal-journal/app.py", line 98, in analyze
urllib.request.urlretrieve(audioURL, input_path)
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 239, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 523, in open
response = meth(req, response)
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 632, in http_response
response = self.parent.error(
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 561, in error
return self._call_chain(*args)
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 494, in _call_chain
result = func(*args)
File "/Users/leochoo/.pyenv/versions/3.9.1/lib/python3.9/urllib/request.py", line 641, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
I look at similar issues, but I could not identify the solution to my situation.
Can't access FireBase Database via HTTP/REST error 403 Forbidden
403 error when passing url as a parameter
requests.get returns 403 while the same url works in browser
urllib.request.urlretrieve ERROR trying to download jpeg in Python
There are a few ways to do this since the ?audioURL={url} parameter is acting as two parameters since it contains a & symbol:
Combine both query parameters that are being received on the python server code instead of the singular one which you have intended to pass through
Encode the audioURL data variable using base64 on client-side then decode on the server-side to keep the special characters that mess up the query param formatting
Glad to have helped!
I have the following snippet of python (2.7.14) which is throwing an exception on the requests.get call. This is running on a FreeBSD server, with an apache front end and all http traffic being redirected to https. Note that I am not overly familiar with python, nor this code. Also the following works fine when running locally on my PC and without https/ssl.
urlstr = getApipath() + 'getData/' + id_data
logging.debug("URL used: %s", urlstr)
try:
resp = requests.get(urlstr)
except Exception as e:
logging.exception("caught exception str: " + str(e))
The urlstr is an api call and is using https. The same api call using curl on the same host's command line returns the expected and valid json.
curl https://my.domain.com/is/api/getData/D_01
The following is the log output including stacktrace when running this (obviously not using real url). Looks like an ssl issue, but the error message string being empty doesn't help. Any help on what the issue could be greatly appreciated.
2018-03-28 10:37:51,530 URL used: https://my.domain.org/is/api/getData/D_01
2018-03-28 10:37:51,531 Starting new HTTPS connection (1): my.domain.org
2018-03-28 10:37:51,540 caught excpetion str: []
Traceback (most recent call last):
File "/var/www/engines/controller/get_data.py", line 25, in getTemplate
resp = requests.get(urlstr)
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python2.7/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
conn.connect()
File "/usr/local/lib/python2.7/site-packages/urllib3/connection.py", line 314, in connect
cert_reqs=resolve_cert_reqs(self.cert_reqs),
File "/usr/local/lib/python2.7/site-packages/urllib3/util/ssl_.py", line 254, in create_urllib3_context
context = SSLContext(ssl_version or ssl.PROTOCOL_SSLv23)
File "/usr/local/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py", line 379, in __init__
self._ctx = OpenSSL.SSL.Context(self.protocol)
File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 724, in __init__
_openssl_assert(res == 1)
File "/usr/local/lib/python2.7/site-packages/OpenSSL/_util.py", line 67, in openssl_assert
exception_from_error_queue(error)
File "/usr/local/lib/python2.7/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
Error: []
An upgrade to the python cryptography module fixed the issue. The installed version was 2.1.4. Turns out there was a newer version available - 2.2.2 which after installing cleared the problem.
I am trying to make a GET request over TOR which is listening on 127.0.0.1:9050
I've installed request socks: pip install -U requests[socks]
import requests
tor_proxy = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'}
r = requests.get("http://www.google.com", proxies=tor_proxy, timeout=20)
Here is the error from when I run the code
Traceback (most recent call last):
r = requests.get("http://www.google.com", proxies=tor_proxy, timeout=20)
File "C:\Python27\lib\site-packages\requests\api.py", line 71, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests\api.py", line 57, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests\adapters.py", line 403, in send
timeout=timeout
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 578, in urlopen
chunked=chunked)
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 362, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python27\lib\httplib.py", line 1057, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1097, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 1053, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 897, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 859, in send
self.connect()
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connection.py", line 167, in connect
conn = self._new_conn()
File "C:\Python27\lib\site-packages\requests\packages\urllib3\contrib\socks.py", line 81, in _new_conn
**extra_kw
File "C:\Python27\lib\site-packages\socks.py", line 195, in create_connection
sock.connect((remote_host, remote_port))
File "C:\Python27\lib\site-packages\socks.py", line 747, in connect
negotiate(self, dest_addr, dest_port)
File "C:\Python27\lib\site-packages\socks.py", line 419, in _negotiate_SOCKS5
CONNECT, dest_addr)
File "C:\Python27\lib\site-packages\socks.py", line 482, in _SOCKS5_request
resolved = self._write_SOCKS5_address(dst, writer)
File "C:\Python27\lib\site-packages\socks.py", line 517, in _write_SOCKS5_address
addr_bytes = socket.inet_pton(family, host)
AttributeError: 'module' object has no attribute 'inet_pton'
Jun 11 13:13:55.000 [notice] Tried for 120 seconds to get a connection to [scrubbed]:0. Giving up. (waiting for socks info)
Thanks
The problem is with the library itself, in particular PySocks socks.py, inet_pton is only available on unix:
socket.inet_pton(address_family, ip_string)
Convert an IP address from its family-specific string format to a packed, binary format. inet_pton() is useful when a library or network protocol calls for an object of type struct in_addr (similar to inet_aton()) or struct in6_addr.
Supported values for address_family are currently AF_INET and AF_INET6. If the IP address string ip_string is invalid, socket.error will be raised. Note that exactly what is valid depends on both the value of address_family and the underlying implementation of inet_pton().
Availability: Unix (maybe not all platforms).
One workaround is to install win_inet_pton and import it in your script, the method will automatically be added to the socket lib.
I'm making a GAE app using Python 2.7.11. This is my first project building a GAE app, and I'm new to web development also. Link here. I am trying to access the Google Book's API in order to retrieve book information. Everything works flawlessly when deployed locally. I type a book's name into the search field, my handler flies off, hits 2 Google APIs (search, then volume), parses the results and appends it to the page.
When I deploy my app to GAE, I get the following error (with stack trace):
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~my-life-app/1.392279800807967905/myapp.py", line 320, in post
response_body = urlopen(request).read()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
Here is the part of my code that performs the API calls. (It's very sloppy, sorry. I've just been trying to fix this issue before cleaning the code up).
headers = {'Accept': 'application/json'}
book = Book(parent=books_key)
book.name = self.request.get('name')
googleBookSearch = "https://www.googleapis.com/books/v1/volumes?q="
googleBookVol = "https://www.googleapis.com/books/v1/volumes/ID"
escapedBookName = urllib.quote(book.name)
apiCall = googleBookSearch + escapedBookName + "&" + api_key2
request = Request(apiCall, headers=headers)
response_body = urlopen(request).read()
parsed_book = json.loads(response_body)
if parsed_book['totalItems'] != 0:
volumeID = parsed_book['items'][0]['id']
googleBookVol = googleBookVol.replace("ID", volumeID)
googleBookVol = googleBookVol + "?" + api_key2
logging.info(googleBookVol)
request = Request(googleBookVol, headers=headers)
response_body = urlopen(request).read()
response_body = json.loads(response_body)
book.name = response_body['volumeInfo']['title']
pageCount = response_body['volumeInfo']['pageCount']
book.pages = int(pageCount)
bookCover = response_body['volumeInfo']['imageLinks']['smallThumbnail']
book.cover = str(bookCover)
book.published = str(response_body['volumeInfo']['publishedDate'])
book.author = str(response_body['volumeInfo']['authors'][0])
book.put()
self.redirect("/books")
According to Google's API documentation, these APIs are only accessing public data so no OAuth or API key is required. Needless to say, that didn't work. I've added my API Key, which still didn't work. I've enabled Google Books API from the Developer Console. The only thing left to me is Oauth, but my head is spinning trying to read the pages upon pages of documentation, some of which is vastly different to each other, so I don't know what to implement. The web app does not require signing in of any kind, and the API requests only use public data. Thanks.
Is there anyone who can help?
EDIT: This is the log portion of what I got back from Google that I pulled from Cloud Console logs. The first portion is the exact URL as shown also by logging.info.
https://www.googleapis.com/books/v1/volumes?q=Pale+Blue+Dot&key=AIzaSyD9o4jKfQvvCAr8glvom4llEAssu8ojmgk
{
metadata:
{
severity:
"ERROR"
projectId:
"598422355661"
serviceName:
"appengine.googleapis.com"
zone:
"us6"
labels:
{…}
timestamp:
"2016-04-23T17:40:38.988615Z"
projectNumber:
"598422355661"
}
protoPayload:
{
#type:
"type.googleapis.com/google.appengine.logging.v1.RequestLog"
appId:
"s~my-life-app"
versionId:
"1"
requestId:
"571bb39600ff0f15c71037dd9b0001737e6d792d6c6966652d617070000131000100"
ip:
"189.61.48.66"
startTime:
"2016-04-23T17:40:38.988615Z"
endTime:
"2016-04-23T17:40:39.020226Z"
latency:
"0.031611s"
megaCycles:
"20"
method:
"POST"
resource:
"/sign"
httpVersion:
"HTTP/1.1"
status:
500
responseSize:
"870"
referrer:
"http://my-life-app.appspot.com/books"
userAgent:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
urlMapEntry:
"myapp.app"
host:
"my-life-app.appspot.com"
cost:
1.29081e-7
instanceIndex:
-1
instanceId:
"00c61b117cb28d6a28da9eadf0f9ad4279a74be43a1ca345cb"
line:
[
0:
{
time:
"2016-04-23T17:40:38.991900Z"
severity:
"INFO"
logMessage:
"https://www.googleapis.com/books/v1/volumes?q=Pale+Blue+Dot&key=AIzaSyD9o4jKfQvvCAr8glvom4llEAssu8ojmgk"
}
1:
{
time:
"2016-04-23T17:40:39.011339Z"
severity:
"ERROR"
logMessage:
"HTTP Error 403: Forbidden
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~my-life-app/1.392300489206286534/myapp.py", line 333, in post
response_body = urlopen(request).read()
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden"
}
]
appEngineRelease:
"1.9.36"
}
insertId:
"2016-04-23|10:40:40.411640-07|10.106.197.137|1661671430"
log:
"appengine.googleapis.com/request_log"
httpRequest:
{
status:
500
}
operation:
{
id:
"571bb39600ff0f15c71037dd9b0001737e6d792d6c6966652d617070000131000100"
producer:
"appengine.googleapis.com/request_id"
}
}
For future strugglers, make sure to add appropriate country string in your request &country=US
The Books API uses the IP address of the client to geo-locate the user. Since we must honor copyright laws from various countries, and have country-specific rights from publishers, we need to know the country where the requests come from in order to serve the proper content.
source
I'm facing a really strange bug while trying to retrieve a resource via HTTP. It seems to happen with any HTTP client (tried requests and urllib with the same results).
My project uses django, and I run my tests using tox and the standard django command python manage.py test. When I run my test suite and a unit test makes a HTTP request (e.g via requests.get('http://example.com')), the tests fails with an error, the test suite continue until the end, and hangs. I have to manually kill the process via command line.
After some investigations, I put a try / except block arount the http request, and got the following stacktrace:
File "/mycomputer/python3.4/site-packages/requests/api.py", line 68, in get
return request('get', url, **kwargs)
File "/mycomputer/python3.4/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/mycomputer/python3.4/site-packages/requests/sessions.py", line 464, in request
resp = self.send(prep, **send_kwargs)
File "/mycomputer/python3.4/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/mycomputer/python3.4/site-packages/requests/adapters.py", line 370, in send
timeout=timeout
File "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 349, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.4/http/client.py", line 1065, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1103, in _send_request
self.endheaders(body)
File "/usr/lib/python3.4/http/client.py", line 1061, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.4/http/client.py", line 906, in _send_output
self.send(msg)
File "/usr/lib/python3.4/http/client.py", line 841, in send
self.connect()
File "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connection.py", line 155, in connect
conn = self._new_conn()
File "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/mycomputer/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 68, in create_connection
sock = socket.socket(af, socktype, proto)
File "/usr/lib/python3.4/socket.py", line 123, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
TypeError: an integer is required (got type socket)
I really don't understand the problem here. Running the same thing from the command line works perfectly, so it's probably related to my project architecture. Also, running the test suite on another computer fails the same way.
Have anybody meet a similar issue ? What can I do do track down the problem ?
Okay, the problem was caused by HTTPretty, a third-party package I use for mocking.
Somewhere I've read that django is not a full server and can cause problems when you try to use it as one. Perhaps this is one of this cases.
Did you try https://docs.djangoproject.com/en/1.8/topics/testing/advanced/ ?