Repository: fossasia/open-event-server

Issue:
TypeError: string indices must be integers
https://sentry.eventyay.com/eventyay/dev-api/issues/97/

```
TypeError: string indices must be integers
(2 additional frame(s) were not displayed)
...
  File "app/api/auth.py", line 46, in reset_password_post
    email = request.json['data']['email']

TypeError: string indices must be integers
```


Discussion:
@shubham-padia can I take up this issue?
 @Kunalgarg2100 If you've setup the nextgen branch locally, please go ahead.
I am facing `password authentication failed` while trying to setup nextgen branch locally.
I by mistake ran
` ` `
CREATE USER kunal WITH PASSWORD 'password@'
` ` `
during installation. Now when I type
` ` `
CREATE USER kunal WITH PASSWORD 'start'
` ` `
I get this error ![Error screenshot](https://drive.google.com/file/d/0B8NBXP-EfPUhM0pYdnY4bThpcHM/view), please tell how to fix it, I tried deleting the entire repo and cloning it again but it resulted in same error
@Kunalgarg2100 Please use the gitter channel for general doubts, the issues are specific for discussion related to that topic only. Please help us keep this thread clean :smile: 
@shubham-padia I figured out that request.json return a dictionary then why we'll get TypeError? I'm  unable to reproduce the error, can you help me how to proceed?
@shubham-padia Using the below request I'm able to reproduce the error.
![screenshot from 2017-09-22 10-35-07](https://user-images.githubusercontent.com/15686569/30730082-fd5af85e-9f81-11e7-8179-6902cd3f655b.png)
![screenshot from 2017-09-22 10-30-57](https://user-images.githubusercontent.com/15686569/30730110-2f7e2b3a-9f82-11e7-9635-614a0916f39f.png)
So should I handle this error or what to do next?

@rahuldecoded can you share the request in a text format on the issue itself or via pastebin? Its hard to figure out from the image :sweat_smile: 
@shubham-padia Sure. :smiley: Only the data part or the whole request?
The data only

On Oct 3, 2017 11:29 PM, "Rahul Bhattacharjee" <notifications@github.com>
wrote:

> @shubham-padia <https://github.com/shubham-padia> Sure. 😃 Only the data
> part or the whole request?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-orga-server/issues/4466#issuecomment-333927483>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ANRCIeCxq6n7FkZzjtJcdiniKTHznIe-ks5sonYGgaJpZM4PUqc6>
> .
>

@shubham-padia 
-d '{ 
          "data": " ", 
          "email": "123@gmail.com"
     }'
For the above one I'm able to reproduce the error.

But according to the docs data must be as below
-d '{ 
         "data": {
               "email": "123@gmail.com"
          }
     }'
According to this `data` is a dictionary where as `data` is a string in the above one. Please rectify if I'm wrong.
Okay, thanks. Please handle the exception and raise a 400 bad request error
in thus case.

On Oct 4, 2017 2:33 PM, "Rahul Bhattacharjee" <notifications@github.com>
wrote:

> @shubham-padia <https://github.com/shubham-padia>
> -d '{
> "data": " ",
> "email": "123@gmail.com"
> }'
> For the above one I'm able to reproduce the error.
>
> But according to the docs data must be as below
> -d '{
> "data": {
> "email": "123@gmail.com"
> }
> }'
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-orga-server/issues/4466#issuecomment-334094065>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ANRCIWTKo9_ZfIvhCKNlbx09D4-_loXmks5so0njgaJpZM4PUqc6>
> .
>


Resolving patch:
diff --git a/app/api/auth.py b/app/api/auth.py
--- a/app/api/auth.py
+++ b/app/api/auth.py
@@ -43,7 +43,10 @@ def verify_email():
 
 @auth_routes.route('/reset-password', methods=['POST'])
 def reset_password_post():
-    email = request.json['data']['email']
+    try:
+        email = request.json['data']['email']
+    except TypeError:
+        return make_response(jsonify(error="Bad Request Error"), 400)
 
     try:
         user = User.query.filter_by(email=email).one()


Test patch: