Help needed in pinterest_post.py in module 3

I am literally working on this piece of code for the entire day but still could not fix the bug. I was suggested to create a new access token and board id from scratch, so I did that but in vain, the code in Pinterest_post.py is still not working and I am losing patience. The code is returning status as failure. Yes I have checked the 10 times limit, and also created a new access token and board id and also tweaked with exchanging board name with board id. Please any help would be highly appreciated. Please help me.

Hi @entcat, what does the unit testing log say about your scenario?

I have not checked that. I do not know how to read unit testing log? But still I need help in pinterest_post.py.

Trust me, you’ll learn to make sense of the log file in the process. The learnings from the ME isn’t just the coding and API part but for the most part is about debugging our way out of errors.

You can take a pass through the log file and try to get some hint out of it like which part/funcition in your code is causing the error and reason for error etc.

You can share you log file contents here if you still can’t make out anything from it. I can help you read through it. But, take some time first to go through it yourself

I think there is fault in the pinterest_post.py file but here is are the contents of the unit testing log file:-
2020-03-02 17:12:47,727 unitTesting INFO Running pytest
2020-03-02 17:12:59,620 unitTesting INFO ============================= test session starts ==============================
platform linux – Python 3.6.9, pytest-5.3.1, py-1.8.0, pluggy-0.12.0
Django settings: qeats.settings (from ini file)
rootdir: /soumyadubey055-ME_QEATS_REVIEW_MP-057235fc-5ca9-11ea-97eb-e35a92e0b338/soumyadubey055-ME_QEATS_REVIEW_MP, inifile: pytest.ini
plugins: django-3.5.1, mock-1.10.4
collected 3 items

tests/test_views.py …F [100%]

=================================== FAILURES ===================================
________________ TestSocialSharing.test_post_to_pinterest_share ________________

self = <tests.test_views.TestSocialSharing object at 0x3ed77ff75860>

def test_post_to_pinterest_share(self):
    client = Client()
    prefix = os.getenv('USER_SOLUTION')
    if prefix is None:
        prefix = '.'

    image_path = prefix + '/tests/sneakpeak.jpg'
    img_b64 = restaurants.image_uploader.file_path_to_img64(image_path)
    import datetime
    message = 'Great Work!!! Completed module 2 @ {}'.format(str(datetime.datetime.now()))
    request_body = {
                    'imgBase64' : img_b64.decode('utf-8'),
                    'text' : message,
                    'orderId' : '0x12312',
                    'tags' : ['Pinterest', 'Module2'],
                    'share' : ['Pinterest']
                    }
    resp = client.post(r'/qeats/v1/review/share', data=request_body, content_type='application/json')
    resp.status_code == 200
    pinterest_test_util = PinterestTestUtil()
    message_expected = message + ' #Pinterest #Module2'
  assert pinterest_test_util.check_whether_message_is_published(message_expected, image_path)

tests/test_views.py:210:


self = <tests.test_views.PinterestTestUtil object at 0x3ed77ff1d160>
message = ‘Great Work!!! Completed module 2 @ 2020-03-02 17:12:58.576151 #Pinterest #Module2
image_path = ‘/soumyadubey055-ME_QEATS_REVIEW_MP-057235fc-5ca9-11ea-97eb-e35a92e0b338/soumyadubey055-ME_QEATS_REVIEW_MP/tests/sneakpeak.jpg’

def check_whether_message_is_published(self, message, image_path):

    user_pins = self.get_all_pins_from_board()

    if 'data' not in user_pins:
        print('=' * 100)
        print('\n\n\nPinterest API: Looks you have hit the per hour API limit\n\n\n')
        print('=' * 100)
        return False
  for one_pin in user_pins['data']:

E TypeError: ‘NoneType’ object is not iterable

tests/test_views.py:85: TypeError
----------------------------- Captured stdout call -----------------------------
<Response [401]>
{‘status’: ‘failure’, ‘code’: 3, ‘data’: None, ‘message’: ‘Authorization failed.’, ‘endpoint_name’: ‘create_pin’}
=============================== warnings summary ===============================
/usr/local/lib/python3.6/dist-packages/_pytest/junitxml.py:436
/usr/local/lib/python3.6/dist-packages/_pytest/junitxml.py:436: PytestDeprecationWarning: The ‘junit_family’ default value will change to ‘xunit2’ in pytest 6.0.
Add ‘junit_family=legacy’ to your pytest.ini file to silence this warning and make your suite compatible.
_issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)

– Docs: https://docs.pytest.org/en/latest/warnings.html

  • generated xml file: /soumyadubey055-ME_QEATS_REVIEW_MP-057235fc-5ca9-11ea-97eb-e35a92e0b338/soumyadubey055-ME_QEATS_REVIEW_MP/tests.xml -
    ==================== 1 failed, 2 passed, 1 warning in 9.96s ====================

2020-03-02 17:12:59,786 unitTesting INFO Pytest run complete
2020-03-02 17:12:59,801 unitTesting INFO Report generated: {‘tests.test_views.TestSocialSharing.test_post_to_pinterest_share’: ‘TEST_STATUS_FAILURE’, ‘tests.test_views.TestSocialSharing.test_post_to_facebook_share_cli’: ‘TEST_STATUS_SUCCESS’, ‘tests.test_views.TestSocialSharing.test_post_to_facebook_share’: ‘TEST_STATUS_SUCCESS’}

Seems like user_pins['data'] is returning null. I don’t know when exactly this could happen.

Did you check if your image was getting pinned to the board when run manually?

The image is not getting pinned to the board when i run the code pinterest_post.py

So, you have got something wrong in your function. See if you are using the correct API call and also passing the arguments correctly. Check in postman first to see if the API call is correct. Also, try to print out values to know the state of your program.

Thats what i have been telling you. I have checked all that and everything seems ok with that. I got the crio people look into my function and he said to generate a new access token and a board id and everything would be fine after that. I re-did everything but in vain. It is still not working.

Any kind of help. This is really frustrating. The moderators are clearly not helping

I just saw your code, you are not using pinterest board id in your code. The API call can only access any board is by board id and access token. Please rectify this in your code.
Also while making request, there is an error while passing parameter.

I am closing this ticket, since it’s been more than 12 hours and I have not received any response from you.