1

I try to use upwork api in flask to get some information, but it doesn't work. How could I get something from upwork with its api?

file app.py

import os
from flask import *
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
from config import Configuration
from upwork import *
import upwork


# Create Flask app
app = Flask(__name__)
app.config.from_object(Configuration)
db = SQLAlchemy(app)
conn = db.engine
#os.environ['HTTPLIB_CA_CERTS_PATH'] = app.config.get('PATH_PEM')

# Create Migration db
migrate = Migrate(app, db, compare_type=True)
manager = Manager(app)
manager.add_command('db', MigrateCommand)

UP_PUBLIC_KEY = app.config.get('UP_PUBLIC_KEY')
UP_SECRET_KEY = app.config.get('UP_SECRET_KEY')
UP_ACCESS_TOKEN = app.config.get('UP_ACCESS_TOKEN')
UP_ACCEES_TOKEN_SECRET = app.config.get('UP_ACCEES_TOKEN_SECRET')

file view.py:

from app import *


@app.route('/')
def get_from_api():
    client = upwork.Client(UP_PUBLIC_KEY, UP_SECRET_KEY)
    client = upwork.Client(UP_PUBLIC_KEY, UP_SECRET_KEY, oauth_access_token=UP_ACCESS_TOKEN,
                           oauth_access_token_secret=UP_ACCEES_TOKEN_SECRET)
    request_token = client.auth.get_request_token()
    print(request_token)
    pass

When I call "print(request_token)" it prints "null:null"

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • You create the `Client()` object twice. That's not intended, probably? – Martijn Pieters May 07 '19 at 10:27
  • Ah, I see, the documentation does talk about this. You just got your ordering wrong. You don't need to get a new token with `get_request_token()` if you already got a valid token stored in `UP_ACCESS_TOKEN` / `UP_ACCEES_TOKEN_SECRET`. – Martijn Pieters May 07 '19 at 10:33
  • @MartijnPieters But it also doesn't work if I want to get some information. It raise with 404NotFound error. Maybe I need to refresh access tokens somehow using my public and secret keys? F.e. if I use this functions: client = upwork.Client(PUBLIC_KEY, SECRET_KEY, oauth_access_token=ACCESS_TOKEN, oauth_access_token_secret=ACCEES_TOKEN_SECRET) data = {'q': ''} works = client.provider_v2.search_jobs(data=data, page_size=100) --- It rases with 404 error – Ярига Олег May 07 '19 at 20:30
  • I'm not familiar with the Upworks setup or how long tokens are valid for their API, but OAuth 1.0 is pretty limited in that it has no support for application tokens (valid for a long time without having the user validate access each time). What level of access do you need, are you accessing the Upworks API on your own behalf (see and do what your user can see or do) or on behalf of whomever is visiting your website (so if I visited your site, do I need to have an Upworks account)? – Martijn Pieters May 08 '19 at 10:53

1 Answers1

0

please,

  1. check the code in view.py: you redefine client with an access token/secret which doesn't exist (judging by what you describe). As a result, you get 404 for non-existing token-secret pair.

  2. check the documentation at http://upwork.github.io/python-upwork/getting_started.html#simple-example

  3. try to implement a simple request using the only python-upwork library and only after that move the code under the flask, to avoid any unexpected behavior in your code.

mnovozhylov
  • 311
  • 1
  • 3
  • Hi, I try this example http://upwork.github.io/python-upwork/getting_started.html#simple-example. When I do this: print client.auth.get_authorize_url() it prints link "https://www.upwork.com/services/api/auth?oauth_token=None", but when I follow this link, I see only "Unauthorized" page. What's wrong? – Ярига Олег May 14 '19 at 15:41