Repository: fossasia/open-event-server

Issue:
HTTP 500 on Event copy task
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
When trying to use Event copy to copy the event, the server errors out and sends HTTP 500. 

**To Reproduce**
Steps to reproduce the behavior:
1. Use the endpoint to copy an event.

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
It shouldn't error out.

**Stacktrace**
<!-- If applicable, add stacktrace to help explain your problem. -->
```
127.0.0.1 - - [01/Jun/2018 02:34:18] "POST /v1/events/8c1f5609/copy? HTTP/1.1" 500 -
INFO:werkzeug:127.0.0.1 - - [01/Jun/2018 02:34:18] "POST /v1/events/8c1f5609/copy? HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/__init__.py", line 64, in __call__
    return self.app(environ, start_response)
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/event_copy.py", line 74, in create_event_copy
    logo_url = create_save_resized_image(image_file=sponsor.logo_url, resize=False)
  File "/media/srv_twry/work/Projects/Community-Projects/Fossasia/open-event-server/app/api/helpers/files.py", line 78, in create_save_resized_image
    data = urllib.request.urlopen(image_file).read()
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/home/srv_twry/anaconda3/envs/open-event-server/lib/python3.6/urllib/request.py", line 517, in open
    req.timeout = timeout
AttributeError: 'NoneType' object has no attribute 'timeout'

```


Discussion:
This might be the error in `urllib` library itself? Maybe we should use the `requests` library for reading the image in `helpers/files.py`?
wanna work on it
cool, go ahead.
@schedutron Yes i also think so. Let's use requests.
@srv-twry @schedutron 
POST `/v1/events/1/copy`
gives me 
```
{
	"copied": true,
	"id": 2,
	"identifier": "efa1589d"
}
```
Ok so you made any changes ?
No its already working.
It probably occurs when the you define a wrong url as the sponsors/event logo.
@bhaveshAn If you aren't able to reproduce then I can take this one.
>  If you aren't able to reproduce then I can take this one.

Sure

Resolving patch:
diff --git a/app/api/helpers/files.py b/app/api/helpers/files.py
--- a/app/api/helpers/files.py
+++ b/app/api/helpers/files.py
@@ -74,6 +74,9 @@ def create_save_resized_image(image_file, basewidth=None, maintain_aspect=None,
     :param image_file:
     :return:
     """
+    if not image_file:
+        return None
+
     filename = '{filename}.{ext}'.format(filename=get_file_name(), ext=ext)
     data = urllib.request.urlopen(image_file).read()
     image_file = io.BytesIO(data)


Test patch: