Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with the proxy #53

Open
HappyDean opened this issue Feb 15, 2017 · 0 comments
Open

How to deal with the proxy #53

HappyDean opened this issue Feb 15, 2017 · 0 comments

Comments

@HappyDean
Copy link

HappyDean commented Feb 15, 2017

Hi there
I am new in Python and Evernote API.
Currently, I followed other people's advice, doing some simple tests first. When I am home (without proxy), the sample code works fine, but however when I am back to office, there is the proxy, so I am not so sure how to upload the file via proxy. I tested a lot , but nothing seemed to work.
Can someone help me with this issue?!

import sys
import hashlib
import time
from evernote.api.client import EvernoteClient
import thrift.protocol.TBinaryProtocol as TBinaryProtocol
import thrift.transport.THttpClient as THttpClient
import evernote.edam.userstore.UserStore as UserStore
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.notestore.NoteStore as NoteStore
import evernote.edam.type.ttypes as Types
import evernote.edam.error.ttypes as Errors
import getpass
import mimetypes

evernoteHost = "sandbox.evernote.com"
userStoreUri = "https://" + evernoteHost + "/edam/user"
noteStoreUriBase = "https://" + evernoteHost + "/edam/note/"


dev_token ="My develop token"
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()
user = userStore.getUser()
print "Authentication was successful for", user.username

noteStoreUri =  noteStoreUriBase + user.shardId
noteStoreHttpClient = THttpClient.THttpClient(noteStoreUri)
noteStoreProtocol = TBinaryProtocol.TBinaryProtocol(noteStoreHttpClient)
noteStore = NoteStore.Client(noteStoreProtocol)

notebooks = noteStore.listNotebooks(dev_token)
for notebook in notebooks:
  if notebook.defaultNotebook:
    defaultNotebook = notebook

tags = raw_input("Tags (separated by commas): ").split(',')

for arg in sys.argv[1:]:
  print "Uploading", arg, "...",
  sys.stdout.flush()
  filedata = open( arg, 'rb').read()
  md5 = hashlib.md5()
  md5.update(filedata)
  hashHex = md5.hexdigest()

  data = Types.Data()
  data.size = len(filedata)
  data.bodyHash = hashHex
  data.body = filedata

  resource = Types.Resource()
  resource.mime = mimetypes.guess_type( arg)[0]
  resource.data = data

  note = Types.Note()
  note.notebookGuid = defaultNotebook.guid
  note.title = arg
  note.content = '<?xml version="1.0" encoding="UTF-8"?>'
  note.content += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd">'
  note.content += '<en-note>'
  note.content += '<en-media type="' + resource.mime + '" hash="' + hashHex + '"/>'
  note.content += '</en-note>'
  note.created = int(time.time() * 1000)
  note.updated = note.created
  note.resources = [ resource ]
  note.tagNames = tags

  createdNote = noteStore.createNote(dev_token, note)

  print "DONE"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant