Page MenuHomePhabricator

NameError: name 'urlopen' is not defined
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce:
I added this to my docker-compose.override.yml in MediaWiki

services:
    eventlogging:
        image: python
        command: sh -c "pip install . && ./bin/eventlogging-devserver --host 0.0.0.0 --port 80 --verbose"
        working_dir: '/app'
        volumes:
            - ./extensions/EventLogging/devserver:/app:cached

and this in my LocalSettings.php

wfLoadExtension( 'EventLogging' );
wfLoadExtension( 'EventStreamConfig' );


$wgEventLoggingBaseUri = 'http://eventlogging/event';

and then I tried to log an event from MediaWiki (php).

Actual Results

Processing /app
Collecting jsonschema>=0.7
  Downloading jsonschema-3.2.0-py2.py3-none-any.whl (56 kB)
Collecting pygments>=1.5
  Downloading Pygments-2.6.1-py3-none-any.whl (914 kB)
Collecting attrs>=17.4.0
  Downloading attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting six>=1.11.0
  Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting pyrsistent>=0.14.0
  Downloading pyrsistent-0.16.0.tar.gz (108 kB)
Requirement already satisfied: setuptools in /usr/local/lib/python3.8/site-packages (from jsonschema>=0.7->eventlogging-devserver==0.0.0) (47.1.1)
Building wheels for collected packages: eventlogging-devserver, pyrsistent
  Building wheel for eventlogging-devserver (setup.py): started
  Building wheel for eventlogging-devserver (setup.py): finished with status 'done'
  Created wheel for eventlogging-devserver: filename=eventlogging_devserver-0.0.0-py3-none-any.whl size=4660 sha256=a35e358dfc6cc4dff19c24d5b2d88fc327fef646edd8e04253452e417f9db07a
  Stored in directory: /tmp/pip-ephem-wheel-cache-_nsqzru2/wheels/40/5d/89/f38b7a58cbc6f6bdff423c409ca06a097d4abae527d8c17f06
  Building wheel for pyrsistent (setup.py): started
  Building wheel for pyrsistent (setup.py): finished with status 'done'
  Created wheel for pyrsistent: filename=pyrsistent-0.16.0-cp38-cp38-linux_x86_64.whl size=126679 sha256=fd77694dd1c93e3178c01bad03541dc11e3117eb717fefe9ba489a4f72e486a5
  Stored in directory: /root/.cache/pip/wheels/17/be/0f/727fb20889ada6aaaaba861f5f0eb21663533915429ad43f28
Successfully built eventlogging-devserver pyrsistent
Installing collected packages: attrs, six, pyrsistent, jsonschema, pygments, eventlogging-devserver
Successfully installed attrs-19.3.0 eventlogging-devserver-0.0.0 jsonschema-3.2.0 pygments-2.6.1 pyrsistent-0.16.0 six-1.15.0

   ___                        _
  / (_)                    \_|_)                 o
  \__        _   _  _  _|_   |     __   __,  __,     _  _    __,
  /    |  |_|/  / |/ |  |   _|    /  \_/  | /  | |  / |/ |  /  |
  \___/ \/  |__/  |  |_/|_/(/\___/\__/ \_/|/\_/|/|_/  |  |_/\_/|/
-----------------------------------------/|---/|--------------/|----------
  (C) Wikimedia Foundation, 2020         \|   \|              \|

# Ensure the following values are set in LocalSettings.php:
wfLoadExtension('EventLogging');
$wgEventLoggingBaseUri = 'http://localhost:8080/event';

-- Listening to events... ---------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "./bin/eventlogging-devserver", line 119, in handle_event
    event, errors = validate(log_line)
  File "./bin/eventlogging-devserver", line 94, in validate
    schema = eventlogging.schema.get_schema(scid, encapsulate=True)
  File "/usr/local/lib/python3.8/site-packages/eventlogging/schema.py", line 59, in get_schema
    schema = http_get_schema(scid)
  File "/usr/local/lib/python3.8/site-packages/eventlogging/schema.py", line 77, in http_get_schema
    schema = json.loads(http_get(url))
  File "/usr/local/lib/python3.8/site-packages/eventlogging/schema.py", line 46, in http_get
    req = urlopen(url)
NameError: name 'urlopen' is not defined
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "./bin/eventlogging-devserver", line 119, in handle_event
    event, errors = validate(log_line)
  File "./bin/eventlogging-devserver", line 94, in validate
    schema = eventlogging.schema.get_schema(scid, encapsulate=True)
  File "/usr/local/lib/python3.8/site-packages/eventlogging/schema.py", line 59, in get_schema
    schema = http_get_schema(scid)
  File "/usr/local/lib/python3.8/site-packages/eventlogging/schema.py", line 77, in http_get_schema
    schema = json.loads(http_get(url))
  File "/usr/local/lib/python3.8/site-packages/eventlogging/schema.py", line 46, in http_get
    req = urlopen(url)
NameError: name 'urlopen' is not defined

Expected Results
Listen and log the events instead of throwing an error and failing.

Event Timeline

dbarratt created this task.Jul 7 2020, 7:03 PM
Restricted Application added a project: Analytics. · View Herald TranscriptJul 7 2020, 7:03 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I suppose a solution to this problem would be to have the devserver in a custom image. That would also make it easier to use with Docker. :) Though that might be unrelated to the actual problem. :)

Change 610144 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/extensions/EventLogging@master] devserver: Import missing 'urlopen'

https://gerrit.wikimedia.org/r/610144

dbarratt closed this task as Resolved.Jul 7 2020, 8:28 PM
dbarratt claimed this task.
dbarratt reassigned this task from dbarratt to Krinkle.

Change 610144 merged by jenkins-bot:
[mediawiki/extensions/EventLogging@master] devserver: Import missing 'urlopen'

https://gerrit.wikimedia.org/r/610144