-1

I have a simple Flask application hosting a form for a data input into local db. I am validating one of the field with wdsl service with python zeep (simply checks if VAT exists with http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl) The application server is behind corporate proxy. Both http_proxy and https_proxy are set. wdsl service returns data as intended while testing (localhost, or running validation function directly with python) When I run the app with Apache2, suddenly the network is unreachable. I believe I have missing some configuration in Flaskapp.conf which would route the traffic through the corporate proxy. Could anybody help/direct me here? Thank you.

urlib3 error:

File "/home/administrator/v_env/flaskapp/lib/python3.6/site-packages/urllib3/connection.py", line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/administrator/v_env/flaskapp/lib/python3.6/site-packages/urllib3/util/connection.py", line 96, in create_connection
raise err
File "/home/administrator/v_env/flaskapp/lib/python3.6/site-packages/urllib3/util/connection.py", line 86, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable 

Flaskapp.conf

<VirtualHost *:80>
                ServerName $stationIP
                ServerAdmin name@domain.com
                WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/FlaskApp/FlaskApp/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

validation function

    def validate_vat(self, vat):
        transport = Transport(timeout=10)
        try:
            client = Client('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', transport=transport)
            client.transport.session.proxies = {'http':'http://<proxy.server.com>:9090'}
            response = client.service.checkVat(vat.data[0:2].upper(), vat.data[2:])
        except:
            raise wtforms.validators.ValidationError('VAT validation service unavailable. Please try again later')

        if not response.valid:
            raise wtforms.validators.ValidationError('Not a valid VAT')
  • I don't understand this downvoting and removing tags of apache and flask by davidism. I believe this is really connected to Apache server and Flask. There is an apache.conf file (Flaskapp.conf) in my post and all the behavior happens only while the Flask app is run through Apache webserver. Until then, everything works as expected. – Pjotruk Prekeder Sep 20 '21 at 09:47
  • So there is nothing wrong with the code above. Tried to add a ProxyRemote directive to FlaskApp.conf, not a change. After a long time spent by searching, I found this question on serverfault.com - [link](https://serverfault.com/questions/977009/apache-proxyremote-does-nothing/977051). What it needed was basically to configure Apache2 trough /etc/apache2/envvars by adding `export http_proxy=':` – Pjotruk Prekeder Sep 23 '21 at 12:37

1 Answers1

0

Configuring Apache2 trough /etc/apache2/envvars by adding export http_proxy='<your_proxy>:<port>' fixed this issue.