Git Product home page Git Product logo

python_tutorial's People

Contributors

jasonjoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python_tutorial's Issues

Getting 400 while trying to create an event through post

I am trying to create an event through your sample, but always getting 400 error

def make_api_call(method, url, token, user_email, payload=None, parameters=None):
    # Send these headers with all API calls
    headers = {'User-Agent': 'python_tutorial/1.0',
               'Authorization': 'Bearer {0}'.format(token),
               'Accept': 'application/json',
               'X-AnchorMailbox': user_email}

    # Use these headers to instrument calls. Makes it easier
    # to correlate requests and responses in case of problems
    # and is a recommended best practice.
    request_id = str(uuid.uuid4())
    instrumentation = {'client-request-id': request_id,
                       'return-client-request-id': 'true'}

    headers.update(instrumentation)

    response = None

    if (method.upper() == 'GET'):
        response = requests.get(url, headers=headers, params=parameters)
    elif (method.upper() == 'DELETE'):
        response = requests.delete(url, headers=headers, params=parameters)
    elif (method.upper() == 'PATCH'):
        headers.update({'Content-Type': 'application/json'})
        response = requests.patch(
            url, headers=headers, data=json.dumps(payload), params=parameters)
    elif (method.upper() == 'POST'):
        headers.update({'Content-Type': 'application/json'})
        response = requests.post(url, headers=headers,
                                 data=json.dumps(payload), params=parameters)

    return response

def create_event(access_token, user_email):
    get_events_url = graph_endpoint.format('/me/events')
    new_event_payload = {
        "subject": "My event",
        "start": {
            "dateTime": "2017-06-19T10:18:29.866Z",
            "timeZone": "UTC"
        },
        "end": {
            "dateTime": "2017-06-26T10:18:29.866Z",
            "timeZone": "UTC"
        },
    }
    r = make_api_call('POST', get_events_url, access_token,
                      user_email, parameters=new_event_payload)
    if (r.status_code == requests.codes.ok):
        print('success')
        print((r.json())['value'])
        return r.json()
    else:
        print('failure')
        print("{0}: {1}".format(r.status_code, r.text))
        return "{0}: {1}".format(r.status_code, r.text)


400: {
  "error": {
    "code": "BadRequest",
    "message": "Query option 'start' was specified more than once, but it must be specified at most once.",
    "innerError": {
      "request-id": "ea2e6c08-866e-471b-9183-5d4bdb3a9739",
      "date": "2017-06-19T10:43:19"
    }
  }
}

Current response with JWT differs from one's expected in tutorial example

Hello,

Today, our auth code (which is based on this tutorials) for Outlook accounts started to crash, because JWT format had changed. Currently it looks like:

{
u'ver': u'2.0', 
u'aud': u'b27e9f81-dbc4-4d4a-923a-3eacaae45241', 
u'iss': u'https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0', 
u'at_hash': u'A9zHQW2pywcdHzwmqdcGpg', 
u'exp': 1456497726, 
u'tid': u'9188040d-6c67-4c5b-b112-36a304b66dad', 
u'iat': 1456411326, 
u'sub': u'AAAAAAAAAAAAAAAAAAAAAEd_FVIeg7D50-KulnCFDGo'
}

Fields preferred_username and name are absent. Quick googling gives nothing ... documentation on Microsoft's dev portal also does not display any updates.
Can you shed some light on this?
Thanks a lot.

Getting user_email from id_token does not work

Hello,

Got next response with access_token and stuff:

resp = {u'id_token_expires_in': u'86400', u'access_token': u'EwB4Aul3BAAUo4xeBIbHjhBxWOFekj4Xy2fhaGQAARR...W9g4MZQE=', u'id_token': u'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ikd2blBBcGZXTWRMUmk4UERtaXNGbjdicHJLZyJ9.eyJ2ZXIiOiIyLjAiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vOTE4ODA0MGQtNmM2Ny00YzViLWIxMTItMzZhMzA0YjY2ZGFkL3YyLjAiLCJhdWQiOiI4MDRjZTgzMy0xNzQ0LTQyNjMtYWUwZC1jZDVhNTQwYzkyYTIiLCJleHAiOjE0Mzk1MzkzMDIsImlhdCI6MTQzOTQ1MjkwMiwiYXRfaGFzaCI6Ii0tSi1Pakt5S1EwdjlTWHY1MTE3WGciLCJuYW1lIjoiRG1pcnR5aSBUZXN0b2RmaiIsInByZWZlcnJlZF91c2VybmFtZSI6ImRtaXRyaXl0ZXN0b3ZpY2g1QG91dGxvb2suY29tIiwic3ViIjoiQUFBQUFBQUFBQUFBQUFBQUFBQUFBTDBqS29XSFdzY1hxQWgtcXdQd3dwVSIsInRpZCI6IjkxODgwNDBkLTZjNjctNGM1Yi1iMTEyLTM2YTMwNGI2NmRhZCJ9.UHtqGoE10KUvldBDWtQ8thCvZUzVC1n7C-N0YJOlKdZ7jN36XwSbCdPhTkqqsVnBXU3Plb4a9KApLIdQ-snjHYuARmDrhnXGsX9BU14pWrJi2leQDPIdk9MjdhhtQ3K51yOdmsVkgpHS7QnZIhYq8tFkmjVWhC8Mr6XR_gnJlto', u'expires_in': u'3600', u'token_type': u'Bearer', u'scope': u'https://outlook.office.com/mail.readwrite'}
id_token = resp['id_token']
token_parts = id_token.split('.')
encoded_token = token_parts[1]
leftovers = len(encoded_token) % 4
leftovers
>> 0
decoded = base64.urlsafe_b64decode(encoded_token).decode('utf-8')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-05cf3c707231> in <module>()
----> 1 decoded = base64.urlsafe_b64decode(encoded_token).decode('utf-8')

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.pyc in urlsafe_b64decode(s)
    110     The alphabet uses '-' instead of '+' and '_' instead of '/'.
    111     """
--> 112     return b64decode(s, '-_')
    113
    114

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.pyc in b64decode(s, altchars)
     69     """
     70     if altchars is not None:
---> 71         s = _translate(s, {altchars[0]: '+', altchars[1]: '/'})
     72     try:
     73         return binascii.a2b_base64(s)

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.pyc in _translate(s, altchars)
     34     for k, v in altchars.items():
     35         translation[ord(k)] = v
---> 36     return s.translate(''.join(translation))
     37
     38

TypeError: character mapping must return integer, None or unicode

where is the problem?

requirements.txt contains null characters

When cloning this repo, installing requirements from the provided requirements.txt fails with the error

Traceback (most recent call last):
  File "/home/username/.local/bin/pipenv", line 10, in <module>
    sys.exit(cli())
  [...]
  File "/home/username/.local/lib/python3.7/site-packages/pipenv/patched/notpip/_internal/req/constructors.py", line 207, in install_req_from_line
    looks_like_dir = os.path.isdir(p) and (
  File "/usr/lib/python3.7/genericpath.py", line 42, in isdir
    st = os.stat(s)
ValueError: embedded null byte

Interestingly, if I open a text editor I find a null character (\x00) between every other character. Deleting them fixes the problem.

I am using Ubuntu 19.10 and Python 3.7.

Sending emails with attachments.

Not really related to python-tutorial, but related to using Outlook Mail REST API in python :) And I'd say that extending tutorial with answer to my question will be very beneficial (googling does not help me at all).

So, I'm trying to use next API method: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessages. Sending messages without attachments works just fine, but I can not understand how to send message with attachments. According to docs, Message structure can contain array of Attachments with items of type https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesFileAttachment Problem is in the field ContentBytes -- it is impossible to dump bytes to JSON before sending request to this API method (actually dumping any BLOB to JSON is nonsense).
How should we pass Attachments using REST API at all, and specifically using python requests (or any other library)?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.